need excel to repeat oddly :)

  • Thread starter Thread starter gotzoom
  • Start date Start date
G

gotzoom

starting with number 7334

7334
7334
7335
7335
7335
7335
7335
7335
7335
7335
7335
7335
7335
7335
7335
7335
7335
7335
7335
7336- 8 times
7337- 7 times
7338- 6 times
7339- 7 times
7340- 8 times
7341- 7 times
7342- 4 times
7343- 8 times
7344- 6 times
7345- 4 times
7346- 6 times

then I need it to repeat from the top, but the next number would be i
sequence...7347

I need this to go to 761
 
starting with number 7334
7334 [2 times]
7335 [17 times]
7336- 8 times
7337- 7 times
7338- 6 times
7339- 7 times
7340- 8 times
7341- 7 times
7342- 4 times
7343- 8 times
7344- 6 times
7345- 4 times
7346- 6 times

then I need it to repeat from the top, but the next number would be in
sequence...7347

I need this to go to 7619

Try this:

Dim n As Long
Dim lngR As Variant ' Table of repeat controls
Dim myR As Variant ' Each element of lngR
Dim lngRow As Long ' Row where to put the number
Dim lngNumber As Long ' The number to be written

Const FIRST As Long = 7334
Const LAST As Long = 7619
lngR = Array(2, 17, 8, 7, 6, 7, 8, 7, 4, 8, 6, 4, 6)

lngNumber = FIRST
lngRow = 2 ' Start in Row 2 (and use Column "B")
Do While lngNumber <= LAST
Cells(lngRow, 3) = "New cycle" ' Unnecessary; only for control
For Each myR In lngR ' Cycle through lngR
For n = 1 To myR ' Write the number repeatedly
Cells(lngRow, 2) = lngNumber
lngRow = lngRow + 1
Next n ' Inner repeat cycle (same number)
lngNumber = lngNumber + 1
Next myR
Loop

This will write 1980 rows, which is fortuitous because

Sum(lngR) * ((LAST-FIRST+1)/(UBound(lngR)-LBound(lngR)+1)) = 1980
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top