Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.newusers
external usenet poster
 
Posts: 1
Default Excel/VBA Automatic Numbering

Hey,

I am trying to use a macro to get my excel worksheet to number
automatically (the rows)....however when i insert a row, the number
tracking is off and there is no automatic numbering...

This is the code I am using:

Sub Autonumber()
done = 0
X = 2
Do While done < 1
If (Cells(X, 1) = "") Then
entry = X - 1
done = 1
Else
X = X + 1
End If
Loop

Cells(X, 1) = entry
X = entry + 1


End Sub

Can anyone please help me ASAP!!!

THANKS :)

Munny Khera

  #2   Report Post  
Posted to microsoft.public.excel.newusers
external usenet poster
 
Posts: 3,365
Default Excel/VBA Automatic Numbering

Try putting this code into the Worksheet's code area:

Private Sub Worksheet_Change(ByVal Target As Range)

If Target.Rows.Count = 1 And _
Target.Address = "$" & Target.Row & ":$" & Target.Row Then
Range("A" & Target.Row).Formula = "=Row()-1"
End If

End Sub

To get to the proper place to put the code, right-click on the worksheet's
tab and choose [View Code] from the list. Copy the above code and paste it
in. Repeat for all sheets you need this function on.

What it does - it tests to see if you've inserted a row by first asking if
the count of rows in the current selection (Target) is one AND if that is
true, by seeing if the address returned for the Target looks like a row
address, $6:$6 for example if you'd just inserted a new row 6.

The formula =ROW()-1
returns the row number -1, so at row 6 it would display 5. I presume that's
what you wanted based on what I saw in your code.

Hope this helps some.

" wrote:

Hey,

I am trying to use a macro to get my excel worksheet to number
automatically (the rows)....however when i insert a row, the number
tracking is off and there is no automatic numbering...

This is the code I am using:

Sub Autonumber()
done = 0
X = 2
Do While done < 1
If (Cells(X, 1) = "") Then
entry = X - 1
done = 1
Else
X = X + 1
End If
Loop

Cells(X, 1) = entry
X = entry + 1


End Sub

Can anyone please help me ASAP!!!

THANKS :)

Munny Khera


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
Automatic Numbering Fortune Excel Worksheet Functions 1 January 22nd 07 03:14 PM
excel automatic numbering Spice Excel Discussion (Misc queries) 4 April 25th 06 07:04 PM
Automatic Quote Numbering Roni Excel Discussion (Misc queries) 2 June 29th 05 08:37 PM
How do I set up invoice automatic numbering in excel? Tracy Excel Discussion (Misc queries) 1 March 22nd 05 05:31 PM
automatic sequential numbering in excel or word greg2 Excel Discussion (Misc queries) 1 January 15th 05 05:35 PM


All times are GMT +1. The time now is 04:21 AM.

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"