View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.misc
Bob Phillips Bob Phillips is offline
external usenet poster
 
Posts: 10,593
Default Automatic Number Formula

Is this what you mean?

Private Sub Worksheet_Change(ByVal Target As Range)
Const WS_RANGE As String = "A:A" '<=== change to suit
Dim nMax As Long

On Error GoTo ws_exit:
Application.EnableEvents = False
If Not Intersect(Target, Me.Range(WS_RANGE)) Is Nothing Then
With Target
If .Value = "Invoice" And .Offset(0, 2).Value = "" Then
nMax = Me.Evaluate("MAX(IF(A1:A1000=""Invoice"",C1:C1000) )")
.Offset(0, 2).Value = nMax + 1
End If
End With
End If

ws_exit:
Application.EnableEvents = True
End Sub

'This is worksheet event code, which means that it needs to be
'placed in the appropriate worksheet code module, not a standard
'code module. To do this, right-click on the sheet tab, select
'the View Code option from the menu, and paste the code in.





--
HTH

Bob Phillips

(replace somewhere in email address with gmail if mailing direct)

"FJ" wrote in message
...
Hi, I need to create an automatic numbering formula in Excel that will

work
as follows: For every row that has the word "Invoice" in cell A1, I want
cell C1 to number automatically. There are also blank rows in the
spreadsheet, and there will be rows added and deleted from time to time.

Is
there any way to write a formula to automatically number something like

this,
updating the numbering when rows are added and deleted? I've tried

various
"IF" and "COUNT" formulas, but to no avail. I hope I've explained this
clearly. Thanks in advance for any information. :)