VBA code to Add serial numbers to a range of cells in Excel


 

Sub AddSerialNumbers()

    Dim i As Long

    Dim LastRow As Long

    

    'Replace A1:A10 with the range you want to add serial numbers to

    LastRow = Range("A1:A10").Cells(Rows.Count, 1).End(xlUp).Row

    

    For i = 1 To LastRow

        'Replace A1 with the first cell of your range

        Range("A1").Offset(i - 1, 0).Value = i

    Next i

End Sub


This code will add serial numbers starting from 1 to the last row of the range specified in the code. Replace "A1:A10" with the range you want to add serial numbers to. You can also change the starting number of the serial numbers by modifying the "i = 1" in the For loop.


Post a Comment

0 Comments
* Please Don't Spam Here. All the Comments are Reviewed by Admin.