Merge and Label cells if same value

How do I merge cells of same value then label each row of the merged cell by a serial number?
Assuming I have this:This is what I haveand I am trying to achieve this:This is what I want to achieve
I found a way to merge the cells if they are of the same value
For i = 4 To Range("A" & Rows.Count).End(xlUp).Row
    If Cells(i, 1) <> "" Then
        If Cells(i, 1) = Cells(i - 1, 1) Then
            Range(Cells(i, 1), Cells(i - 1, 1)).Merge
        End If
    End If

Open in new window


Any suggestions on how I can proceed with the labelling? Maybe a "do while", but I'm not sure how to make sure it restarts from 1 if the adjacent cell is not merged.
Pearlyn TanAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Rgonzo1971Commented:
Hi,

pls try
Columns("B").Insert
RowIdx = 4
Cnt = 1
For idx = 4 To Range("A" & Rows.Count).End(xlUp).Row
    If Cells(idx, 1) = Cells(RowIdx, 1) Then
        Application.DisplayAlerts = False
        Range(Cells(idx, 1), Cells(RowIdx, 1)).Merge
        Application.DisplayAlerts = True
    Else
        RowIdx = idx
        Cnt = 1
    End If
    Cells(idx, 2) = Cnt
    Cnt = Cnt + 1
Next

Open in new window

Regards
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Pearlyn TanAuthor Commented:
Works perfect. Thank you very much!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
VBA

From novice to tech pro — start learning today.