Forum Discussion

Corder's avatar
Corder
Copper Contributor
Mar 28, 2022
Solved

Formula to Duplicate Entire Rows Based on Cell Value

Hello everyone!   I'm trying to create a formula that will duplicate an entire row based on a cell's value. Below is a mock photo of what I am hoping to accomplish:     The formula would g...
  • OliverScheurich's avatar
    Mar 28, 2022

    Corder 

    Sub companyemployees()
    
    Dim i As Double
    Dim j As Double
    Dim z As Double
    Dim w As Double
    
    For i = 2 To 1000
    
    j = Cells(i, 2).Value
    
    For z = 2 To j + 1
    
    Cells(z + w, 4).Value = Cells(i, 1).Value
    Cells(z + w, 5).Value = Cells(i, 2).Value
    
    Next z
    w = w + z - 2
    
    Next i
    
    End Sub

     

    Maybe with these lines of VBA code. Click the button in cell G2 in the attached file to start the macro.

Resources