Duplicate line and decrease Id number

- - Latest reply: ac3mark
Posts
10940
Registration date
Monday June 3, 2013
Status
Moderator
Last seen
December 14, 2018
- 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.
See more 

Your reply

1 reply

Posts
10940
Registration date
Monday June 3, 2013
Status
Moderator
Last seen
December 14, 2018
0
Thank you
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!
Respond to ac3mark