re:"I would accept the instances always being in the same column."
I had a go to allow instances in multiple columns and came up with the
vba below.
A few points, at this late stage:
1.I've used Long instead of Integer as I often got an overflow error.
2.I had a problem when the first line(s) of the spreadsheet had not
been used, so changed it as Paul suggested to
Number_Of_Rows = Range(Selection, Selection.End(xlDown)).Count
but got a perceptible delay sometimes as it ran through all the rows
on the sheet, dependent on which cell was selected before running, so
despite knowing that xlCellTypeLastCell can on occasion be
idiosyncratic, I used that instead.
3.It renumbers the sequence regardless of which columns they're in,
and gives sequence numbers on the same row the same number (hope
that's how you wanted it!).
4.It might be wise to give the function a more obcsure name since I've
used Find which looks for '=seq(' anywhere in the cell, not just at
the left, so it's just conceivable that it could be found as part of
text elsewhere.
5.I've not tested as rigourously as I usually do, since it's just a
suggestion - you seem to have the problem solved to your satisfaction
already.
Private Sub RecalcSeq()
Dim i As Long
Dim Number_Of_Rows As Long
Dim Seq_Number As Long
' Determine number of rows containing data
Number_Of_Rows = Selection.SpecialCells(xlCellTypeLastCell).Row
Seq_Number = 0
For i = 1 To Number_Of_Rows
With Rows(i)
Set c = .Find(What:="=seq(", LookIn:=xlFormulas, _
LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False)
If Not c Is Nothing Then
firstAddress = c.Address
Seq_Number = Seq_Number + 1
Do
c.Formula = "=seq(" & Seq_Number & ")"
Set c = .FindNext(c)
Loop While Not c Is Nothing And c.Address <> firstAddress
End If
End With
Next i
End Sub