IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Macros et VBA Excel Discussion :

(XL 2021 )Range("f2").End(xlDown).Offset(1).Select erreur si juste une ligne


Sujet :

Macros et VBA Excel

Mode arborescent

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre averti
    Femme Profil pro
    Responsable de compte
    Inscrit en
    Décembre 2021
    Messages
    22
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Âge : 57
    Localisation : Canada

    Informations professionnelles :
    Activité : Responsable de compte
    Secteur : Administration - Collectivité locale

    Informations forums :
    Inscription : Décembre 2021
    Messages : 22
    Par défaut (XL 2021 )Range("f2").End(xlDown).Offset(1).Select erreur si juste une ligne
    Bonjour,

    J'utilise Office famille et petite entreprise 2021 sur Windows 11

    J’ai une macro qui fonctionne très bien sauf si j'ai seulement une ligne dans mon tableau.

    Voici les explications

    J’ai un classeur pour les réceptions de marchandise
    Je télécharge un fichier .csv qui est mon bon de commande créer dans shopify

    Voici le résultat en deux images beaucoup trop larges pour juste une (j'ai changé pour des donner fictive)


    Nom : 2067 partie 1.jpg
Affichages : 391
Taille : 102,3 Ko
    Nom : 2067 partie 2.jpg
Affichages : 386
Taille : 74,9 Ko


    Les colonnes que j'ai besoin de garder sont:

    Purchase Order (a)
    Vendor/Supplier (d)
    Product (f)
    SKU (h)
    Retail Price (t)
    Qty Ordered (v)
    Cost (base) (y)
    Total Cost (base) (z)


    Je supprime les autres colonnes

    Je corrige la largeur des colonnes restante
    Je garde les 2 dernière pour les renommées

    Cost (supplier currency) (aa)
    et
    Total Cost (supplier currency) (ab)

    Margin et Margin%

    Dans la nouvelle colonne Margin j'ajoute ma formule

    Range("I2").Formula = "=[@[Retail Price]]-[@[Cost (base)]]"

    Dans celle Margin%

    Range("J2").Formula = "=([@Margin]/[@[Retail Price]])*100"

    Ensuite je change les . pour des , dans les colonne ("e:h")

    Je veux avoir la somme de la colonne Qty Ordered et Total Cost (base)

    J'utilise Range("f2").End(xlDown).Offset(1).Select pour aller la première cellule vide de la colonne pour faire la somme des Qty Ordered et ensuite pour la colonne Total Cost (base)

    C'est ici que j'ai un problème.


    Certaine bon de commande on juste une ligne et ça me donne une erreur d'exécution 1004

    Nom : 2067 partie 3.jpg
Affichages : 451
Taille : 98,2 Ko


    Voici le code de la macro au complet
    Elle n'est pas professionnel mais elle me facilite beaucoup mon travail.
    merci de votre aide


    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    Sub Margin()
     
      Columns("W:X").Delete
      Columns("U:U").Delete
      Columns("I:S").Delete
      Columns("G:G").Delete
      Columns("E:E").Delete
      Columns("B:C").Delete
      Columns("A:A").ColumnWidth = 5.86
      Columns("B:B").ColumnWidth = 9
      Columns("E:E").ColumnWidth = 9.43
      Columns("F:F").ColumnWidth = 6.14
      Columns("G:G").ColumnWidth = 8.43
      Columns("H:H").ColumnWidth = 5.71
      Columns("I:I").ColumnWidth = 6.71
      Columns("J:J").ColumnWidth = 9
      Columns("I:I").ColumnWidth = 9
      Columns("J:J").ColumnWidth = 9
     With Range("E2:H1000")
        .HorizontalAlignment = xlHAlignCenter
        .VerticalAlignment = xlVAlignBottom
      End With
     
        Range("I1") = "Margin"
        Range("J1") = "Margin%"
        Dim last_row As Long
        last_row = Cells(Rows.Count, 2).End(xlUp).Row
        Range("I2").Formula = "=[@[Retail Price]]-[@[Cost (base)]]"
        Range("J2").Formula = "=([@Margin]/[@[Retail Price]])*100"
        Range("J2").NumberFormat = "#,##0.00"
        If last_row = 2 Then GoTo AfterAutoFill
        Range("i2").AutoFill Destination:=Range("i2:i" & last_row)
        Range("J2").AutoFill Destination:=Range("J2:J" & last_row)
    AfterAutoFill:
               Set plg = Range("e:h")
    plg.Replace What:=".", Replacement:=",", LookAt:=xlPart
    plg.Replace What:=",", Replacement:=".", LookAt:=xlPart
    plg.Range("e:h").NumberFormat = "0.00"
            Range("f2").End(xlDown).Offset(1).Select
            ActiveCell.FormulaR1C1 = "=SUM(R" & ActiveCell.Offset(-1, 0).End(xlUp).Row & "C" & ActiveCell.Column & ":R" & ActiveCell.Row - 1 & "C" & ActiveCell.Column & ")"
            Range("h2").End(xlDown).Offset(1).Select
            ActiveCell.FormulaR1C1 = "=SUM(R" & ActiveCell.Offset(-1, 0).End(xlUp).Row & "C" & ActiveCell.Column & ":R" & ActiveCell.Row - 1 & "C" & ActiveCell.Column & ")"
     
        ActiveSheet.PageSetup.Orientation = xlLandscape
        Application.PrintCommunication = False
        With ActiveSheet.PageSetup
            .PrintTitleRows = ""
            .PrintTitleColumns = ""
        End With
        Application.PrintCommunication = True
        ActiveSheet.PageSetup.PrintArea = ""
        Application.PrintCommunication = False
        With ActiveSheet.PageSetup
            .LeftHeader = ""
            .CenterHeader = ""
            .RightHeader = ""
            .LeftFooter = ""
            .CenterFooter = ""
            .RightFooter = ""
            .LeftMargin = Application.InchesToPoints(0.7)
            .RightMargin = Application.InchesToPoints(0.7)
            .TopMargin = Application.InchesToPoints(0.75)
            .BottomMargin = Application.InchesToPoints(0.75)
            .HeaderMargin = Application.InchesToPoints(0.3)
            .FooterMargin = Application.InchesToPoints(0.3)
            .PrintHeadings = False
            .PrintGridlines = False
            .PrintComments = xlPrintNoComments
            .CenterHorizontally = False
            .CenterVertically = False
            .Orientation = xlLandscape
            .Draft = False
            .PaperSize = xlPaperLetter
            .FirstPageNumber = xlAutomatic
            .Order = xlDownThenOver
            .BlackAndWhite = False
            .Zoom = False
            .FitToPagesWide = 1
            .FitToPagesTall = 0
            .PrintErrors = xlPrintErrorsDisplayed
            .OddAndEvenPagesHeaderFooter = False
            .DifferentFirstPageHeaderFooter = False
            .ScaleWithDocHeaderFooter = True
            .AlignMarginsHeaderFooter = True
            .EvenPage.LeftHeader.Text = ""
            .EvenPage.CenterHeader.Text = ""
            .EvenPage.RightHeader.Text = ""
            .EvenPage.LeftFooter.Text = ""
            .EvenPage.CenterFooter.Text = ""
            .EvenPage.RightFooter.Text = ""
            .FirstPage.LeftHeader.Text = ""
            .FirstPage.CenterHeader.Text = ""
            .FirstPage.RightHeader.Text = ""
            .FirstPage.LeftFooter.Text = ""
            .FirstPage.CenterFooter.Text = ""
            .FirstPage.RightFooter.Text = ""
        End With
        Application.PrintCommunication = True
    End Sub
    Images attachées Images attachées  
    Fichiers attachés Fichiers attachés

Discussions similaires

  1. Code VBA Range and End(xlDown)
    Par MP45000 dans le forum Macros et VBA Excel
    Réponses: 3
    Dernier message: 15/05/2018, 10h00
  2. [XL-2010] Probleme de variable dans Range("B5", [B5].End(xlDown))
    Par CnamExcel dans le forum Excel
    Réponses: 12
    Dernier message: 11/03/2016, 20h59
  3. [XL-2003] Dernière cellule : .End(xlDown) ne marche pas
    Par shakur221 dans le forum Macros et VBA Excel
    Réponses: 2
    Dernier message: 15/05/2009, 13h28

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo