Macro petit problème avec boucle for

Bonjour forum ,

J'ai un petit souci avec ma macro, elle colle des formules sur plusieurs feuilles nommées Feuil1, Feuil2 etc etc seulement dès que

 If Nblig = 1 Then Exit Sub

ce sont mes entêtes, la macro s'arrête sur la feuille x qui aura qu'une ligne non vide donc c'est normal, mais je voudrais quelle continue sur les Feuilles suivante dont les lignes seront supérieure a 1 !

Voilà je demande vôtre aide.

Voici le code

Sub Formules()
    Dim ws As Worksheet
    Dim Nblig As Long

    For Each ws In ThisWorkbook.Worksheets

        If ws.Name Like "Feuil*" Then
            With ws

                .Select
                Nblig = .Cells(Rows.Count, "A").End(xlUp).Row

                 If Nblig = 1 Then Exit Sub

                .Range("O2:O" & Nblig) = "=MIN(RC[-3]:RC[-1])"
                .Range("P2:P" & Nblig) = "=(RC[-7]-RC[-10])/RC[-10]"
                .Range("Q2:Q" & Nblig) = "=(RC[-7]-RC[-10])/RC[-10]"
                .Range("R2:R" & Nblig) = "=(RC[-7]-RC[-10])/RC[-10]"
                .Range("S2:S" & Nblig) = "=MIN(RC[-3]:RC[-1])"
                .Cells.Columns.AutoFit
            End With
        End If
    Next ws

End Sub

bonsoir,

une proposition, non testée

Sub Formules()
    Dim ws As Worksheet
    Dim Nblig As Long

    For Each ws In ThisWorkbook.Worksheets

        If ws.Name Like "Feuil*" Then
            With ws

                .Select
                Nblig = .Cells(Rows.Count, "A").End(xlUp).Row

                 If Nblig >1 Then            
                 .Range("O2:O" & Nblig) = "=MIN(RC[-3]:RC[-1])"
                 .Range("P2:P" & Nblig) = "=(RC[-7]-RC[-10])/RC[-10]"
                 .Range("Q2:Q" & Nblig) = "=(RC[-7]-RC[-10])/RC[-10]"
                 .Range("R2:R" & Nblig) = "=(RC[-7]-RC[-10])/RC[-10]"
                 .Range("S2:S" & Nblig) = "=MIN(RC[-3]:RC[-1])"
                 .Cells.Columns.AutoFit
                End If
            End With
        End If
    Next ws

End Sub

Bah écoute ça fonctionne nickel Merci bcp h2so4 pour ta réponse rapide

Rechercher des sujets similaires à "macro petit probleme boucle"