Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 20
Default Macro to autonumber cells

I have an excel sheet where I want to be able to select a range of cells in a
column and have excel automatically number them based on the value in a
previous row.

e.g. if A1 = 1, and I select A2 through A4, I want to be able to
automatically number A2 to A4 as 1.1, 1.2, 1.3. The idea is that if I then
insert a new row between A2 and A3, I could select the new A2 through A5 and
renumber as 1.1 through 1.4.

I hope Ive made it clear what I am after.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,089
Default Macro to autonumber cells

Jim

one way:

Sub AutoNumberCells()

Dim iCount As Integer
Dim BaseNumber As String
Dim cell As Range

iCount = 1
BaseNumber = Selection(1).Offset(-1, 0)

For Each cell In Selection
cell.Value = BaseNumber & "." & iCount
iCount = iCount + 1
Next 'cell

End Sub

Regards

Trevor


"JimG" wrote in message
...
I have an excel sheet where I want to be able to select a range of cells in
a
column and have excel automatically number them based on the value in a
previous row.

e.g. if A1 = 1, and I select A2 through A4, I want to be able to
automatically number A2 to A4 as 1.1, 1.2, 1.3. The idea is that if I
then
insert a new row between A2 and A3, I could select the new A2 through A5
and
renumber as 1.1 through 1.4.

I hope I've made it clear what I am after.



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 34
Default Macro to autonumber cells

The following appears to work for me, however, I also select the row that I
want to use as the number the following rows are based on. In your example,
just select A1 through A4 instead of A2 through A4.

Sub RenumRow()
Dim i As Integer, j As Integer
Dim cell As Range

j = 0

For Each cell In Selection
If Selection.Range("a1").Row = cell.Row Then
i = cell.Value
Else
j = j + 1
cell.Value = i & "." & j
End If
Next cell

End Sub

"JimG" wrote:

I have an excel sheet where I want to be able to select a range of cells in a
column and have excel automatically number them based on the value in a
previous row.

e.g. if A1 = 1, and I select A2 through A4, I want to be able to
automatically number A2 to A4 as 1.1, 1.2, 1.3. The idea is that if I then
insert a new row between A2 and A3, I could select the new A2 through A5 and
renumber as 1.1 through 1.4.

I hope Ive made it clear what I am after.

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
Drag cells autonumber feature went bye bye?!?!? [email protected] Excel Discussion (Misc queries) 2 February 16th 07 05:05 PM
Can Excel AutoNumber Globe Director Excel Discussion (Misc queries) 3 July 27th 06 09:48 AM
Autonumber from Form ES New Users to Excel 2 February 7th 06 04:58 PM
autonumber Hardy Excel Discussion (Misc queries) 4 November 24th 05 05:40 PM
Question on autonumber Xenos Excel Programming 5 October 2nd 05 08:14 PM


All times are GMT +1. The time now is 07:54 PM.

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

About Us

"It's about Microsoft Excel"