Nombre de lignes dans une macro

Bonjour,

J'ai enregistré une macro pour la mise en forme d'un tableau.

Dans mon exemple, le tableau contient 8530 lignes.

Le problème c'est lorsque j'exécute cette macro sur un autre tables qui contient un nombre différent de 8530 comme ligne, certaines cellule n'obéissent pas (ou j'aurai des cellules en plus).

Y'a-t-il un moyen pour y remédier.

Merci.

Sub MISE_EN_FORME_TABLEAU()

'

' MISE_EN_FORME_TABLEAU Macro

' ELIMINER LES LIGNES INUTILES. REPARER LES ERREURS DE LA COLONNE MIN_PLANNED.

'

'

Rows("1:15").Select

Range("A15").Activate

Selection.Delete Shift:=xlUp

Columns("O:O").Select

Selection.Replace What:=".", Replacement:=",", LookAt:=xlPart, _

SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _

ReplaceFormat:=False

Selection.TextToColumns Destination:=Range("O1"), DataType:=xlDelimited, _

TextQualifier:=xlDoubleQuote, ConsecutiveDelimiter:=False, Tab:=True, _

Semicolon:=False, Comma:=False, Space:=False, Other:=False, FieldInfo _

:=Array(1, 1), TrailingMinusNumbers:=True

Range("R1").Select

ActiveCell.FormulaR1C1 = "MACHINE"

Range("R2").Select

ActiveCell.FormulaR1C1 = "=VLOOKUP(RC[-8],MACHINE,2,FALSE)"

Range("R2").Select

Selection.AutoFill Destination:=Range("R2:R8530")

Range("R2:R8530").Select

Range("S1").Select

ActiveCell.FormulaR1C1 = "TYPE_USCHALL_1"

Range("S2").Select

ActiveCell.FormulaR1C1 = "=VLOOKUP(RC[-8],TYPE_USCHALL_1,2,FALSE)"

Range("S2").Select

Selection.AutoFill Destination:=Range("S2:S8530")

Range("S2:S8530").Select

Range("T1").Select

ActiveCell.FormulaR1C1 = "DPG_CONCERNE_1"

Range("T2").Select

ActiveCell.FormulaR1C1 = "=IF(RC[-1]<>"""",RC[-15],0)"

Range("T2").Select

Selection.AutoFill Destination:=Range("T2:T8530")

Range("T2:T8530").Select

Range("U1").Select

ActiveCell.FormulaR1C1 = "DPG_CONCERNE_2"

Range("U2").Select

ActiveCell.FormulaR1C1 = "=IF((COUNTIF(C[-1],RC[-16])>0)=TRUE,RC[-16],0)"

Range("U2").Select

Selection.AutoFill Destination:=Range("U2:U8530")

Range("U2:U8530").Select

ActiveWindow.SmallScroll Down:=-15

Columns("T:T").Select

Selection.Copy

Columns("V:V").Select

Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _

:=False, Transpose:=False

Columns("S:S").Select

Application.CutCopyMode = False

Selection.Copy

Columns("W:W").Select

Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _

:=False, Transpose:=False

Range("X1").Select

Application.CutCopyMode = False

ActiveCell.FormulaR1C1 = "AFFECTATION_USCHALL"

Range("X2").Select

ActiveCell.FormulaR1C1 = "=VLOOKUP(RC[-3],C[-2]:C[-1],2,0)"

Range("X2").Select

Selection.AutoFill Destination:=Range("X2:X8530")

Range("X2:X8530").Select

ActiveWindow.SmallScroll Down:=-12

End Sub

Le forum,

À tester sur des copies de fichier ... sûrement d'autres améliorations seront nécessaires.

Dans VBE (touches ALT-F11), la touche F8 fait du pas à pas pour suivre le déroulement de la macro.

Spoiler

Sub MISE_EN_FORME_TABLEAU()

'

' MISE_EN_FORME_TABLEAU Macro

' ELIMINER LES LIGNES INUTILES. REPARER LES ERREURS DE LA COLONNE MIN_PLANNED.

Dim DerLig As Long

' ajuster au nom de la feuille et ajuster la colonne au besoin

DerLig = Worksheets("Feuil1").Range("A" & Rows.Count).End(xlUp).Row

Rows("1:15").Select

Selection.Delete Shift:=xlUp

Columns("O:O").Replace What:=".", Replacement:=",", LookAt:=xlPart, _

SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _

ReplaceFormat:=False

Columns("O:O").TextToColumns Destination:=Range("O1"), DataType:=xlDelimited, _

TextQualifier:=xlDoubleQuote, ConsecutiveDelimiter:=False, Tab:=True, _

Semicolon:=False, Comma:=False, Space:=False, Other:=False, FieldInfo _

:=Array(1, 1), TrailingMinusNumbers:=True

Range("R1").FormulaR1C1 = "MACHINE"

Range("R2").FormulaR1C1 = "=VLOOKUP(RC[-8],MACHINE,2,FALSE)"

Range("R2").AutoFill Destination:=Range("R2:R" & DerLig)

Range("S1").FormulaR1C1 = "TYPE_USCHALL_1"

Range("S2").FormulaR1C1 = "=VLOOKUP(RC[-8],TYPE_USCHALL_1,2,FALSE)"

Range("S2").AutoFill Destination:=Range("S2:S" & DerLig)

Range("T1").FormulaR1C1 = "DPG_CONCERNE_1"

Range("T2").FormulaR1C1 = "=IF(RC[-1]<>"""",RC[-15],0)"

Range("T2").AutoFill Destination:=Range("T2:T" & DerLig)

Range("U1").FormulaR1C1 = "DPG_CONCERNE_2"

Range("U2").FormulaR1C1 = "=IF((COUNTIF(C[-1],RC[-16])>0)=TRUE,RC[-16],0)"

Range("U2").AutoFill Destination:=Range("U2:U" & DerLig)

Columns("T:T").Copy

Columns("V:V").Select

Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _

:=False, Transpose:=False

Application.CutCopyMode = False

Columns("S:S").Copy

Columns("W:W").Select

Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _

:=False, Transpose:=False

Application.CutCopyMode = False

Range("X1").FormulaR1C1 = "AFFECTATION_USCHALL"

Range("X2").FormulaR1C1 = "=VLOOKUP(RC[-3],C[-2]:C[-1],2,0)"

Range("X2").AutoFill Destination:=Range("X2:X" & DerLig)

Range("X2").Select

End Sub

Jim

Bonjour,

A tester.

Option Explicit
' MISE_EN_FORME_TABLEAU Macro
' ELIMINER LES LIGNES INUTILES. REPARER LES ERREURS DE LA COLONNE MIN_PLANNED.
Public Sub MISE_EN_FORME_TABLEAU()
Dim N As Long

    With ActiveSheet

        N = .Cells(.Rows.Count, "O").End(xlUp).Row

        .Rows("1:15").Delete Shift:=xlUp

        .Columns("O:O").TextToColumns Destination:=Range("O1"), _
                                      DataType:=xlDelimited, _
                                      TextQualifier:=xlDoubleQuote, _
                                      Tab:=True, _
                                      FieldInfo:=Array(1, 1), _
                                      DecimalSeparator:=".", _
                                      TrailingMinusNumbers:=True

        .Range("R1").Value = "MACHINE"
        With .Range("R2")
            .FormulaR1C1 = "=VLOOKUP(RC[-8],MACHINE,2,FALSE)"
            .AutoFill Destination:=.ells(2, "R").Resize(N - 1)
        End With

        Range("S1").FormulaR1C1 = "TYPE_USCHALL_1"
        With .Range("S2")
            .FormulaR1C1 = "=VLOOKUP(RC[-8],TYPE_USCHALL_1,2,FALSE)"
            .AutoFill Destination:=.Cells(2, "S").Resize(N - 1)
        End With

        Range("T1").FormulaR1C1 = "DPG_CONCERNE_1"
        With .Range("T2")
            .FormulaR1C1 = "=IF(RC[-1]<>"""",RC[-15],0)"
            .AutoFill Destination:=.Cells(2, "T").Resize(N - 1)
        End With

        Range("U1").FormulaR1C1 = "DPG_CONCERNE_2"
        With .Range("U2")
            .FormulaR1C1 = "=IF((COUNTIF(C[-1],RC[-16])>0)=TRUE,RC[-16],0)"
            .AutoFill Destination:=.Cells(2, "U").Resize(N - 1)
        End With

        .Columns("T:T").Copy
        .Columns("V:V").PasteSpecial Paste:=xlPasteValues
        Application.CutCopyMode = False

        .Columns("S:S").Copy
        .Columns("W:W").PasteSpecial Paste:=xlPasteValues
        Application.CutCopyMode = False

        .Range("X1").FormulaR1C1 = "AFFECTATION_USCHALL"
        With .Range("X2")
            .FormulaR1C1 = "=VLOOKUP(RC[-3],C[-2]:C[-1],2,0)"
            .AutoFill Destination:=.Cells(2, "X").Resize(N - 1)
        End With

    End With

End Sub

Je vous remercie les amis.

Mais je n'ai toujours pas réussi à résoudre le probléme.

Bonjour,

Envoie ton fichier.

Cdlt.

Bonjour,

Voici le fichier.

Merci pour l'aide.

11vk-planung-325.xlsm (711.22 Ko)

A mon avis, le problème se réside dans ce genre de lignes dans le macro : Selection.AutoFill Destination:=Range("S17:S9036")

C'est parce que lors de son enregestriment, j'ai appliqué la formule dans une cellule puis j'ai fait un double clic pour l'appliquer sur toute la plage de la colonne.

Bonjour,

essaie ceci, inspiré de la proposition de Jean-Eric, que je salue.

Option Explicit
' MISE_EN_FORME_TABLEAU Macro
' ELIMINER LES LIGNES INUTILES. REPARER LES ERREURS DE LA COLONNE MIN_PLANNED.
Public Sub MISE_EN_FORME_TABLEAU()
    Dim N As Long
    With ActiveSheet
        .Rows("1:15").Delete Shift:=xlUp
        N = .Cells(.Rows.Count, "O").End(xlUp).Row
        .Columns("O:O").TextToColumns Destination:=Range("O1"), _
                                      DataType:=xlDelimited, _
                                      TextQualifier:=xlDoubleQuote, _
                                      Tab:=True, _
                                      FieldInfo:=Array(1, 1), _
                                      DecimalSeparator:=".", _
                                      TrailingMinusNumbers:=True
        .Range("R1").Value = "MACHINE"
        .Range("R2").FormulaR1C1 = "=VLOOKUP(RC[-8],MACHINE,2,FALSE)"
        .Range("R2").AutoFill Destination:=.Cells(2, "R").Resize(N - 1)
        .Range("S1").FormulaR1C1 = "TYPE_USCHALL_1"
        .Range("S2").FormulaR1C1 = "=VLOOKUP(RC[-8],TYPE_USCHALL_1,2,FALSE)"
        .Range("S2").AutoFill Destination:=.Cells(2, "S").Resize(N - 1)
        .Range("T1").FormulaR1C1 = "DPG_CONCERNE_1"
        .Range("T2").FormulaR1C1 = "=IF(RC[-1]<>"""",RC[-15],0)"
        .Range("T2").AutoFill Destination:=.Cells(2, "T").Resize(N - 1)
        .Range("U1").FormulaR1C1 = "DPG_CONCERNE_2"
        .Range("U2").FormulaR1C1 = "=IF((COUNTIF(C[-1],RC[-16])>0)=TRUE,RC[-16],0)"
        .Range("U2").AutoFill Destination:=.Cells(2, "U").Resize(N - 1)
        .Columns("T:T").Copy
        .Columns("V:V").PasteSpecial Paste:=xlPasteValues
        .Columns("S:S").Copy
        .Columns("W:W").PasteSpecial Paste:=xlPasteValues
        .Range("X1").FormulaR1C1 = "AFFECTATION_USCHALL"
        .Range("X2").FormulaR1C1 = "=VLOOKUP(RC[-3],C[-2]:C[-1],2,0)"
        .Range("X2").AutoFill Destination:=.Cells(2, "X").Resize(N - 1)
    End With
    Application.CutCopyMode = False
End Sub

Bonjour,

Voici le code que j'ai pu trouvé et qui m'a bien depanné :

Dim DL As Integer 'déclare al variable DL (Dernière Ligne)

DL = Cells(Application.Rows.Count, "E").End(xlUp).Row 'définit la derniere ligne DL de la colonne E (colonne à adapter à ton cas)

Range("S16").Value = "MACHINE_3311_1"

Range("S17").FormulaR1C1 = "=VLOOKUP(RC[-9],MACHINE,2,FALSE)"

Range("S17").AutoFill Destination:=Range("S17:S" & DL), Type:=xlFillDefault

Le même principe s'applique sur le reste des colonnes.

Bonne journée !

Rechercher des sujets similaires à "nombre lignes macro"