Excel formular for numbering cells

Hello,

Can you please help me to write a formula for numbering only cells that have "Component" name in it? Please see attached file. I started to number them one by one manually, but it takes too long. I stopped at 256 count.
BOM.xls
Iryna253Asked:
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.

Saurabh Singh TeotiaCommented:
Their you go your file with the data..all i did just ran this code which does what you are looking for..

Sub cmp()
    Dim rng As Range, cell As Range
    Dim lrow As Long, r As Range
    lrow = Cells(Cells.Rows.Count, "b").End(xlUp).Row
    Set rng = Range("B4:B" & lrow)

    For Each cell In rng

        If InStr(1, cell.Value, "Component:", vbTextCompare) > 0 Then
            Set r = Range("A4:A" & cell.Row - 1)
            cell.Offset(0, -1).Value = Application.WorksheetFunction.Max(r) + 1
        End If

    Next cell


End Sub

Open in new window


Saurabh...
BOM.xls
Subodh Tiwari (Neeraj)Excel & VBA ExpertCommented:
Or simply this.....
Sub SequenceNumber()
    Dim rng As Range, cell As Range
    Dim lrow As Long, r As Long
    lrow = Cells(Cells.Rows.Count, "B").End(xlUp).Row
    Set rng = Range("B4:B" & lrow)
    For Each cell In rng
        If cell Like "Component*" Then
            r = r + 1
            cell.Offset(0, -1).Value = r
        End If
    Next cell
End Sub

Open in new window

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
Iryna253Author Commented:
Can you please advise if I need to number rows with a word "Parts" in it ("Non-inventory Parts:" and "Parts:"). How to modify the code? I attached a file.
rptRequirements2.xls
OWASP Proactive Controls

Learn the most important control and control categories that every architect and developer should include in their projects.

Subodh Tiwari (Neeraj)Excel & VBA ExpertCommented:
Like this.....

Set rng = Range("A4:A" & lrow)
For Each cell In rng
    If cell Like "*Parts*" Then
      r = r + 1

Open in new window

But then the line cell.Offset(0, -1).Value = r will produce an error because column A is the first column with those values and no column to it's left is not available to put the sequence numbers.
Iryna253Author Commented:
I am having hard time to do it. I added one more column and it is still make an error. Can you please advise?
rptRequirementsA600.xls
Subodh Tiwari (Neeraj)Excel & VBA ExpertCommented:
Well I don't see that you have inserted a column. Are you talking about rows?

Or place the numbering on the sheet manually for few items and highlight those numbering, that would help to know where exactly you would like to place the numbering and upload it here.
Iryna253Author Commented:
Yes. I would like to number rows with "Parts" word in it. I started to do it manually but it is too time consuming. I also highlighted the column in yellow to show where I want to have numbering.
rptRequirementsA600.xls
Subodh Tiwari (Neeraj)Excel & VBA ExpertCommented:
Try this.....

Sub SequenceNumber()
    Dim rng As Range, cell As Range
    Dim lrow As Long, r As Long
    lrow = Cells(Cells.Rows.Count, "B").End(xlUp).Row
    Set rng = Range("B4:B" & lrow)
    For Each cell In rng
        If cell Like "*Parts:*" Then
            r = r + 1
            cell.Offset(0, -1).Value = r
        End If
    Next cell
End Sub

Open in new window

Refer to the attached workbook and click on the button Insert Sequence No. to insert the numbering in column A.
rptRequirementsA600.xls
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
Microsoft Excel

From novice to tech pro — start learning today.