Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
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.





  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 18
Default macro to add an auto serial number column

hi guys.
Manage to resolve the "integer" boolean statement with IsNumeric.

Luckily I do not use numbers as the label for column A. Otherwise it would
not work.

Here is how I coded it:

With historyWks

'Adding a serial numbers into column A starting with value 1
If IsNumeric(historyWks.Cells(nextRow, "A").Offset(-1, 0))
Then
historyWks.Cells(nextRow, "A").Value = historyWks.Cells(nextRow,
"A").Offset(-1, 0).Value + 1
Else
historyWks.Cells(nextRow, "A").Value = 1
End If
oCol = 2
For Each myCell In myRng.Cells
historyWks.Cells(nextRow, oCol).Value = myCell.Value
oCol = oCol + 1
Next myCell
End With

"Blubber" wrote:

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.





  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 3,365
Default macro to add an auto serial number column

Glad you found your problem, I was about to say that you were going to have
problems if the column was initially empty, since it would find row 1 as the
result of the .End(xlUp).Row statement and there is no row 0 so later when
you used the .Offset(-1,0) function, it would fail.

"Blubber" wrote:

hi guys.
Manage to resolve the "integer" boolean statement with IsNumeric.

Luckily I do not use numbers as the label for column A. Otherwise it would
not work.

Here is how I coded it:

With historyWks

'Adding a serial numbers into column A starting with value 1
If IsNumeric(historyWks.Cells(nextRow, "A").Offset(-1, 0))
Then
historyWks.Cells(nextRow, "A").Value = historyWks.Cells(nextRow,
"A").Offset(-1, 0).Value + 1
Else
historyWks.Cells(nextRow, "A").Value = 1
End If
oCol = 2
For Each myCell In myRng.Cells
historyWks.Cells(nextRow, oCol).Value = myCell.Value
oCol = oCol + 1
Next myCell
End With

"Blubber" wrote:

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.





  #4   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 18
Default macro to add an auto serial number column

Wow, that did not occur to me. However I have permanantly defined labels in
the worksheet so I am ok.

Thanks A mil JLatham.

"JLatham" wrote:

Glad you found your problem, I was about to say that you were going to have
problems if the column was initially empty, since it would find row 1 as the
result of the .End(xlUp).Row statement and there is no row 0 so later when
you used the .Offset(-1,0) function, it would fail.

"Blubber" wrote:

hi guys.
Manage to resolve the "integer" boolean statement with IsNumeric.

Luckily I do not use numbers as the label for column A. Otherwise it would
not work.

Here is how I coded it:

With historyWks

'Adding a serial numbers into column A starting with value 1
If IsNumeric(historyWks.Cells(nextRow, "A").Offset(-1, 0))
Then
historyWks.Cells(nextRow, "A").Value = historyWks.Cells(nextRow,
"A").Offset(-1, 0).Value + 1
Else
historyWks.Cells(nextRow, "A").Value = 1
End If
oCol = 2
For Each myCell In myRng.Cells
historyWks.Cells(nextRow, oCol).Value = myCell.Value
oCol = oCol + 1
Next myCell
End With

"Blubber" wrote:

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.





Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Auto Serial No Abdul Shakeel Excel Discussion (Misc queries) 1 October 17th 08 12:11 PM
A Macro to find missing serial numbers in a column Khoshravan Excel Discussion (Misc queries) 9 August 6th 06 10:37 AM
Auto number / macro creation Fiona Excel Discussion (Misc queries) 2 March 7th 05 07:05 AM
Auto number w/ different letter-number combos in same column Colleen B Excel Worksheet Functions 2 February 23rd 05 02:41 PM
Set the serial number every 15th column SJ Excel Discussion (Misc queries) 2 February 23rd 05 01:39 AM


All times are GMT +1. The time now is 12:29 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"