PDA

View Full Version : [SOLVED] Insert progressive numbers in a column but every n rows



RIC63
12-10-2018, 08:18 AM
Good morning,


I'm looking for a code that inserts a progressive number every n rows, starting from 1 up to a given number. I think it's not complicated, but I do not have the knowledge to write the code, can someone help me?

I enclose an example to better explain what I mean


thank you

mikerickson
12-10-2018, 08:53 AM
Something like


Dim targetN as Long
Dim x as Long
Dim RowNum as Long, RowInterval as Long
x=0
TargetN = 34
RowNum = 1
RowInterval = 4

Do Until TargetN <= X
X = X +1
Cells(RowNum, 1).Value = x
RowNum = RowNum + RowInterval
Loop

大灰狼1976
12-10-2018, 10:40 PM
Hi RIC63!
You can do like this

Private Sub CommandButton1_Click()
Dim cnt&, stp&, i&, arr
cnt = [i1]: stp = [i2]
ReDim arr(1 To cnt, 1 To 1)
arr(1, 1) = 1
For i = stp To cnt Step stp
arr(i, 1) = i
Next i
[a1].Resize(cnt) = arr
End Sub
Please refer to the attachment.

RIC63
12-14-2018, 08:15 AM
Thank you mikerickson (http://www.vbaexpress.com/forum/member.php?10706-mikerickson)

it works well, it's just what I wanted
Thanks again
riccardo