Duplicate line and decrease Id number

Closed
Jean - Oct 31, 2018 at 03:28 PM
 Blocked Profile - Oct 31, 2018 at 04:01 PM
Hi

Does anybody know how I can repeat rows in a spreadsheet (or into another spreadsheet) by n number of times specified in the cell in that row with a decremental id

ie from this table:

Column A Column B Column C
Peter 123 3
James 32 7
David 90 4

I need to produce this table:
Column A Column B Column C
Peter 123 3
Peter 122 3
Peter 121 3
James 32 7
James 31 7
James 30 7
James 29 7
James 28 7
James 27 7
James 26 7
David 90 4
David 89 4
David 88 4
David 87 4

Any ideas on a simple way of doing this?

Any help would be greatly appreciated.

1 reply

Blocked Profile
Oct 31, 2018 at 04:01 PM
Umm, this is a simple for loop:

a = 1
b = ThisWorkbook.Worksheets(1).Range("C1").Value
decVal = ThisWorkbook.Worksheets(1).Range("B1").Value
For n = a To b
newval = decVal - n
MsgBox (n & " is the Count for " & ThisWorkbook.Worksheets(1).Range("A1").Value & "s value of " & newval)
Next

This is the best start you could ever have for your homework. I hope this helped. I WILL NOT MODIFY IT based on your findings that it doesn't do exactly what you want. It does what you asked!

Have FUN!
0