How to make excel sheet generates an auto number

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!!
 
G

Guest

Put in ThisWorkbook module

Private Sub Workbook_Open()
[A1]=[A1]+1
End Sub

"ghost" skrev:
 
G

Guest

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
 
G

Guest

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top