Insert/Replace with Sequential Number as a letter/symbol occur down on a column

seeke

New Member
Joined
Jul 13, 2012
Messages
4
In column A, I have a symbol "#" occur in random rows; a "#" in one whole cell; i.e. an "#" in A2, A4, or A35, throughout to A4390.
I want to insert a sequential number next to the "#" as it occurs down the column.
So the first "#" would be replaced as "#1"; then the second "#" would be "#2"; the 3rd "#" would be "#3"; then the 134th "#" would be "#134";

Thank you so much. By the way, this is my first time here, and I'm pretty new to excel. I've spent sometime searching for the solution, but without knowledge of macro/codes, I'm not even sure whether I have already found the solution (or similar to the solution), so I decided to post question specifically regarding my situation.

-seeke
 

Excel Facts

Spell Check in Excel
Press F7 to start spell check in Excel. Be careful, by default, Excel does not check Capitalized Werds (whoops)
Hi Seeke and welcome to the Board
try this
Code:
Sub seq()
Dim lr As Long, r As Long, c As Integer
lr = Cells(Rows.Count, "A").End(xlUp).Row
c = 1
    For r = 1 To lr
        If Range("A" & r).Value = "#" Then
            Range("A" & r).Value = "#" & c
            c = c + 1
        End If
    Next r
End Sub
 
Upvote 0
Since you have several thousand rows, this might run a bit faster than Michael's code:
Code:
Sub PoundSignAddendum()
Const sFnd As String = "#"
Dim lR As Long, R As Range, F As Range, i As Long, fAdr As String
lR = Range("A" & Rows.Count).End(xlUp).Row
Set R = Range("A1", "A" & lR)
With R
    Set F = .Find(what:=sFnd, after:=[A1], LookIn:=xlValues, _
        lookat:=xlWhole, searchorder:=xlByRows, _
        searchdirection:=xlNext)
    If F Is Nothing Then Exit Sub
    fAdr = F.Address
    i = 1
    Do
        F.Value = F.Value & i
        i = i + 1
        Set F = .FindNext(F)
        If F Is Nothing Then Exit Sub
    Loop While F.Address <> fAdr
 End With
End Sub
 
Upvote 0
Thanks Joe! It works. :)
Michael's works too, until it was bugged out shortly by a cell with "#NAME?" (which I'd need to fix) instead of "#" alone.

Nevertheless, thanks so much Michael and Joe; that was quick.

-seeke
 
Upvote 0

Forum statistics

Threads
1,216,070
Messages
6,128,614
Members
449,460
Latest member
jgharbawi

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top