How to make excel sheet generates an auto number

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Greeting,
I have work book and I need this work book generates an auto number. For
example, when I open this sheet for the first time, A1 =1, next time =2 and
so on. Is that possible in excel???
Thanks!!
 
Add this code in excel:

Private Sub Workbook_Open()
Dim i As Integer
Dim iValue As Integer
Dim iStart As Integer
Dim iIncrement As Integer
i = 1
iStart = 1 'Here you can define the starting value
iIncrement = 1 'Here you can define the incremenatal value

If Cells(1, 1).Value = "" Then
Cells(1, 1).Value = iStart
Else
While Cells(i, 1).Value <> ""
iValue = Cells(i, 1).Value
i = i + 1
Wend
Cells(i, 1).Value = iValue + iIncrement
End If

ActiveWorkbook.Save

End Sub

Thanks,
Mahesh
 
it works.
thanks a lot

Mahesh said:
Add this code in excel:

Private Sub Workbook_Open()
Dim i As Integer
Dim iValue As Integer
Dim iStart As Integer
Dim iIncrement As Integer
i = 1
iStart = 1 'Here you can define the starting value
iIncrement = 1 'Here you can define the incremenatal value

If Cells(1, 1).Value = "" Then
Cells(1, 1).Value = iStart
Else
While Cells(i, 1).Value <> ""
iValue = Cells(i, 1).Value
i = i + 1
Wend
Cells(i, 1).Value = iValue + iIncrement
End If

ActiveWorkbook.Save

End Sub

Thanks,
Mahesh
 
Back
Top