I have tried to create dynamic for loop with the start and end numbers being variables. However, the code cannot get into the for loop with the changed start and end numbers. How could I solve my problem?
Here is my code
Sub row_column()
Dim ws As Worksheet
Set ws = ThisWorkbook.Worksheets("origin_boundary")
Row = 1
Dim Start As Integer
Start = 2
Dim Last As Integer
Last = 41
For x = Start To (Last + 1)
If ws.Cells(x, 1) <= Row * 40 Then
ws.Cells(x, 6) = Row
Else
If ws.Cells(x, 1) > (Row * 40) Then
Row = Row + 1
ws.Cells(x, 6) = Row
Start = (Row - 1) * 40 + 2
Last = Start + 39
End If
End If
Next x
End Sub