Microsoft 365 Comment dupliquer des lignes autant de fois que l'indication d'une cellule?

Boostez vos compétences Excel avec notre communauté !

Rejoignez Excel Downloads, le rendez-vous des passionnés où l'entraide fait la force. Apprenez, échangez, progressez – et tout ça gratuitement ! 👉 Inscrivez-vous maintenant !

TheoAngel10

XLDnaute Nouveau
Bonjour,
J'ai dans un tableau 8 colonnes. Je souhaite reproduire chaque ligne en fonction du nb indiqué dans la colonne H à l'identique pour les colonnes A à G et ceci chaque fois que la valeur est supérieur à 1.
Auriez-vous une idée de code vba ou formule excel qui permette de faire ceci?
Par avance merci pour votre aide.
Je débute en vba et excel. Je veux utiliser ce fichier pour un travail sur R.
TL
 

Pièces jointes

Hello

Avec ce code par exemple..
VB:
Sub recopie()
Application.ScreenUpdating = False
Dim tabdata() As Variant
With ActiveSheet
    fin = .Range("A" & .Rows.Count).End(xlUp).Row
    tabdata = .Range("A1:H" & fin).Value
End With
Sheets.Add.Name = "Result"
With Sheets("Result")
    indfeuille = 1
    For j = LBound(tabdata, 2) To UBound(tabdata, 2) - 1
        .Cells(indfeuille, j) = tabdata(1, j)
    Next j
    For i = LBound(tabdata, 1) + 1 To UBound(tabdata, 1)
        For cpt = 1 To tabdata(i, 8)
            indfeuille = indfeuille + 1
            For j = LBound(tabdata, 2) To UBound(tabdata, 2) - 1
                .Cells(indfeuille, j) = tabdata(i, j)
            Next j
        Next cpt
    Next i
End With
Application.ScreenUpdating = True
End Sub

vu la quantité de lignes, c'est un peu long..
peut etre qu'en créant un tablofinal plutot que copier directement dans la feuille..
 
un peu plus rapide :-D
VB:
Sub recopie()
Application.ScreenUpdating = False
Dim tabdata() As Variant
Dim tabfinal() As Variant
With ActiveSheet
    fin = .Range("A" & .Rows.Count).End(xlUp).Row
    NbFinal = Application.WorksheetFunction.Sum(Range("H2:H" & fin))
    tabdata = .Range("A1:H" & fin).Value
    ReDim tabfinal(1 To NbFinal + 1, 1 To 7)
End With

    indfeuille = 1
    For j = LBound(tabdata, 2) To UBound(tabdata, 2) - 1
        tabfinal(indfeuille, j) = tabdata(1, j)
    Next j
    For i = LBound(tabdata, 1) + 1 To UBound(tabdata, 1)
        For cpt = 1 To tabdata(i, 8)
            indfeuille = indfeuille + 1
            For j = LBound(tabdata, 2) To UBound(tabdata, 2) - 1
                tabfinal(indfeuille, j) = tabdata(i, j)
            Next j
        Next cpt
    Next i
Sheets.Add.Name = "Result"
With Sheets("Result")
    .Range("A1").Resize(UBound(tabfinal, 1), UBound(tabfinal, 2)) = tabfinal
End With
Application.ScreenUpdating = True
End Sub
 
un peu plus rapide :-D
VB:
Sub recopie()
Application.ScreenUpdating = False
Dim tabdata() As Variant
Dim tabfinal() As Variant
With ActiveSheet
    fin = .Range("A" & .Rows.Count).End(xlUp).Row
    NbFinal = Application.WorksheetFunction.Sum(Range("H2:H" & fin))
    tabdata = .Range("A1:H" & fin).Value
    ReDim tabfinal(1 To NbFinal + 1, 1 To 7)
End With

    indfeuille = 1
    For j = LBound(tabdata, 2) To UBound(tabdata, 2) - 1
        tabfinal(indfeuille, j) = tabdata(1, j)
    Next j
    For i = LBound(tabdata, 1) + 1 To UBound(tabdata, 1)
        For cpt = 1 To tabdata(i, 8)
            indfeuille = indfeuille + 1
            For j = LBound(tabdata, 2) To UBound(tabdata, 2) - 1
                tabfinal(indfeuille, j) = tabdata(i, j)
            Next j
        Next cpt
    Next i
Sheets.Add.Name = "Result"
With Sheets("Result")
    .Range("A1").Resize(UBound(tabfinal, 1), UBound(tabfinal, 2)) = tabfinal
End With
Application.ScreenUpdating = True
End Sub
Un grand merci pour votre aide. Pour l'instant il y a deux bénéficiaires qui se sont rajoutés. A quoi cela pourrait être dû? Je devrais avoir 50 898 lignes + une de titre
 
- Navigue sans publicité
- Accède à Cléa, notre assistante IA experte Excel... et pas que...
- Profite de fonctionnalités exclusives
Ton soutien permet à Excel Downloads de rester 100% gratuit et de continuer à rassembler les passionnés d'Excel.
Je deviens Supporter XLD

Discussions similaires

Réponses
3
Affichages
485
Retour