View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.misc
Blubber Blubber is offline
external usenet poster
 
Posts: 18
Default macro to add an auto serial number column

Hi,
Need help with VB codes.
I am extracting data from a worksheet form into a data collection worksheet.
The worksheet has pre-existing rows of headers and labels.

I want to auto generate the serial numbers in column A of the data
collection worksheet. I am stuck trying to establish the first serial number
as "1".

Is it possible to code such that:
If the cell above is in column A < "integer" then value in active cell = 1
I get a syntex error with the following:-

With historyWks
nextRow = .Cells(.Rows.Count, "A").End(xlUp).Offset(1, 0).Row
End With

If historyWks.Cells(nextRow, "A").Offset(-1, 0) < integer Then
historyWks.Cells(nextRow, "A").Value = 1
Else
historyWks.Cells(nextRow, "A").Value = historyWks.Cells(nextRow,
"A").Offset(-1, 0).Value + 1
End If

'Perhaps there is a better way to do this. Appreciate some help.