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
Who is Participating?

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.

Commented:
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
``````

Saurabh...
BOM.xls
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
``````

Experts Exchange Solution brought to you by

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

Author 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
Excel & VBA ExpertCommented:
Like this.....

``````Set rng = Range("A4:A" & lrow)
For Each cell In rng
If cell Like "*Parts*" Then
r = r + 1
``````
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.
Author 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
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.
Author 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
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
``````
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.