Quite a Difficult Problem, any Help Please :-)

stevie3

New Member
Joined
Mar 14, 2012
Messages
2
Hello Everybody

I am having quite a problem with a spreadsheet I am working on.

I basically need to copy a row, and if the value in cell "V" is greater than 1, then that many rows (as specified in cell "V") need to be inserted below, and the copied row needs to be inserted that many times.

This all needs to occur while still keeping the formatting of the rows that have now moved (as they are linked to another sheet), as well as occuring for all the rows till about 20000.

The macro should also be able to detect when the value in cell "V" is zero, and then simply move on to the next row and go through the process again. Any help please?
 

Excel Facts

Fastest way to copy a worksheet?
Hold down the Ctrl key while dragging tab for Sheet1 to the right. Excel will make a copy of the worksheet.
Welcome to the board.

I think this ought to do it.

Tested on a very small dataset (34 rows) so I've no idea how long it will take. Run it on a copy of your data and go make a coffee.

Code:
Sub test()
    lr = Cells(Rows.Count, "V").End(xlUp).Row
    r = 1
    Application.ScreenUpdating = False
    Do
        v = Val(Cells(r, "V"))
        If v > 0 Then
            Rows(r).Copy
            Rows(r + 1).Resize(v).Insert
            r = r + v + 1
            lr = lr + v
        Else
            r = r + 1
        End If
    Loop Until r > lr
End Sub
HTH
 
Upvote 0

Forum statistics

Threads
1,226,729
Messages
6,192,696
Members
453,747
Latest member
tylerhyatt04

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top