Inserer des données par saut 6 lignes

Bonjour le Forum,

De nouveau je sollicite votre aide pour un petit problème.

J'ai un code qui voici:

Sub Insert()
'
' Ecriture des differentes lignes

Dim Sheetgroup As Worksheet, lig As Long, Derlig As Long

For Each Sheetgroup In ThisWorkbook.Worksheets
    If Sheetgroup.Name = "Output Rows Summary" Or Sheetgroup.Name = "Exports Rows Summary" Then
        With Sheetgroup

            .Range("B9").Value = "MKT+NMKT+OWN_USE"
            .Range("B10").Value = "MKT+NMKT+OWN_USE<=TOT_EGSS"
            .Range("B11").Value = "MKT"
            .Range("B12").Value = "ES_CS+C_REP"
            .Range("B13").Value = "ES_CS+C_REP<=MKT"

        End With
    End If
Next Sheetgroup

End Sub

Ce code permet de remplir plusieurs lignes. Les données sont récurrentes toutes les 6 lignes. Et je dois remplir mes lignes jusqu'à 308ème ligne.

J'aimerais pouvoir écrire une boucle qui puisse dire "Inserts moi cette instruction tout les 6 saut de ligne, entre les lignes 9 et 308"

Par avance Merci.

Cdt,

Abakisi

Bonjour,

Essaye le code suivant :

Sub Insert()
    Dim sh As Worksheet
    For Each sh In ThisWorkbook.Worksheets
        If sh.Name = "Output Rows Summary" Or sh.Name = "Exports Rows Summary" Then
            For i = 9 To 304 Step 5
                With sh
                    .Range("B" & i).Value = "MKT+NMKT+OWN_USE"
                    .Range("B" & i + 1).Value = "MKT+NMKT+OWN_USE<=TOT_EGSS"
                    .Range("B" & i + 2).Value = "MKT"
                    .Range("B" & i + 3).Value = "ES_CS+C_REP"
                    .Range("B" & i + 4).Value = "ES_CS+C_REP<=MKT"
                End With
            Next i
        End If
    Next sh
End Sub

Bonjour,

A tester.

Cdlt.

Option Explicit

' Ecriture des differentes lignes
Sub Insert()
Dim ws As Worksheet
Dim tbl As Variant
Dim I As Integer
Const DEBUT As Integer = 9
Const FIN As Integer = 309

    tbl = Array("MKT+NMKT+OWN_USE", "MKT+NMKT+OWN_USE<=TOT_EGSS", "MKT", "ES_CS+C_REP", "ES_CS+C_REP<=MKT")

    For Each ws In ThisWorkbook.Worksheets
        If ws.Name = "Output Rows Summary" Or ws.Name = "Exports Rows Summary" Then
            With ws
                For I = DEBUT To FIN Step 6
                    .Cells(I, 2).Resize(5).Value = Application.Transpose(tbl)
                Next
            End With
        End If
    Next ws
End Sub

Bonjour Raja,

Merci infiniment c'est juste la perfection.

Cdt

Abakisi


Jean-Eric a écrit :

Bonjour,

A tester.

Cdlt.

Option Explicit

' Ecriture des differentes lignes
Sub Insert()
Dim ws As Worksheet
Dim tbl As Variant
Dim I As Integer
Const DEBUT As Integer = 9
Const FIN As Integer = 309

    tbl = Array("MKT+NMKT+OWN_USE", "MKT+NMKT+OWN_USE<=TOT_EGSS", "MKT", "ES_CS+C_REP", "ES_CS+C_REP<=MKT")

    For Each ws In ThisWorkbook.Worksheets
        If ws.Name = "Output Rows Summary" Or ws.Name = "Exports Rows Summary" Then
            With ws
                For I = DEBUT To FIN Step 6
                    .Cells(I, 2).Resize(5).Value = Application.Transpose(tbl)
                Next
            End With
        End If
    Next ws
End Sub

Bonjour Jean-Eric,

Le résultat de votre code est bleffant aussi voire carrément ce qu'il me faut.

Mais par contre un peu plus complexe à l'écriture. Mais je pense pouvoir arriver à comprendre. Merci beaucoup beaucoup!

Cdt,

Abakisi

Rechercher des sujets similaires à "inserer donnees saut lignes"