Home » excel » excel – Nested loops to add number of a defined length

excel – Nested loops to add number of a defined length

Posted by: admin May 14, 2020 Leave a comment

Questions:

This is an example of my situation.
I have a file with 100,000 rows and I must label the first 2000 with 1 the second 3000 with 2 and so on until the last batch with 50.
In reality, the file doesn’t have 100,000 but is a multiple of the batch of rows to get repeated that is 3190.

A piece of code to start with is as follow:

Sub B()
Dim i As Long
Dim q As Integer
For i = 1 To 169070 Step 3190
    Cells(i, 1).Value = i + 1
Next i
End Sub
How to&Answers:

Try

=FLOOR(ROW()/1000,1)+1

Just add to “Row()” the number of rows above your starting point.