LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #8   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 2,202
Default Auto Numbers in cells

It works on my end, so I am not sure what to say, except perhaps to start
over with a new work sheet. You are placing this formula...

=IF(AND(ROWS($1:4)<49,MOD(ROWS($1:4),2)=0),(ROWS($ 1:4)-2)/2,"")

in cell A4 and then copying it down to cell A48. You are then going to
right-click that sheets tab and select View Code from its popup menu and
then copy/paste this....

Private Sub Worksheet_Change(ByVal Target As Range)
Dim C As Range
If Intersect(Target, Range("A4:A48")) Is Nothing Then Exit Sub
For Each C In Range("A4:A48")
If Not C.HasFormula Then
C.Formula = "=IF(AND(ROWS($1:" & C.Row & ")<49,MOD(ROWS($1:" & _
CStr(C.Row) & "),2)=0),(ROWS($1:" & CStr(C.Row) &
")-2)/2,"""")"
End If
Next
End Sub

into the code window that appeared in the VBA editor. It is important that
the above function be placed in the code window for the sheet where the
auto-numbering is to take place. I just tried it out again to be sure and
performing the above steps produces a working set-up that does what you said
you were after. I have attached an XL2003 worksheet to this posting that has
everything in place so that (if you have XL2003 or XL2007), you can see how
it works.

Rick


"Nathan Elphick" wrote in message
...
Rick,

Thank you - you're too modest!!

I have done as instructed but am getting a Compile Error / Syntax Error
when
inserting and deleting lines - any ideas?

Nathan

"Rick Rothstein (MVP - VB)" wrote:

Brilliant - may thanks.


I don't know about "brilliant", but you are welcome.

I have changed the spreadsheet so that the range is 1 to 23, with 1
starting
in Cell A4 and 23 ending in Cell A48 - How does this effect the code?


Yes, it affects the code and what is put in the spreadsheet initially
(the
code and formulas are location-sensitive). For your latest requirement,
put
this in A4 (note that I said A4, not A1)...

=IF(AND(ROWS($1:4)<49,MOD(ROWS($1:4),2)=0),(ROWS($ 1:4)-2)/2,"")

and copy it down to A48. Replace the function (in the worksheet's code
window) that I gave you earlier with this new function...

Private Sub Worksheet_Change(ByVal Target As Range)
Dim C As Range
If Intersect(Target, Range("A4:A48")) Is Nothing Then Exit Sub
For Each C In Range("A4:A48")
If Not C.HasFormula Then
C.Formula = "=IF(AND(ROWS($1:" & C.Row & ")<49,MOD(ROWS($1:" & _
CStr(C.Row) & "),2)=0),(ROWS($1:" & CStr(C.Row) &
")-2)/2,"""")"
End If
Next
End Sub

Both of the above should do what you have now asked for. Because the
function is in the Worksheet Change event, you will have to make the
above
changes **before** you attempt to erase the formulas you currently have
in
A1:A3 (otherwise the old function will just refill them in for you).

Rick



 
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 select of numbers ekkeindoha Excel Discussion (Misc queries) 1 July 7th 07 09:46 AM
Excel auto formats cells with numbers - Can it be disabled? Jeromey Setting up and Configuration of Excel 1 May 21st 06 01:17 AM
is there a way to auto copy cells similar to auto sum? saki4two Excel Worksheet Functions 1 January 11th 06 08:21 PM
Auto Inserting numbers Buildscharacter Excel Worksheet Functions 1 November 14th 05 04:34 AM
Auto Protecting cells & auto filling date ccarmock Excel Discussion (Misc queries) 7 September 30th 05 09:21 PM


All times are GMT +1. The time now is 02:24 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"