Numbering Cells with Different Groupings of Data

mcsa

New Member
Joined
Jun 22, 2023
Messages
3
Office Version
  1. 2021
Platform
  1. MacOS
Hello, I'm hoping some experts on here can help me. I have a very large sheet with like items grouped together. I'd like to number all the different cells, but only number the first cell of like items. I've attached an image of how I'd like it numbered. I can't use the "counta if isblank" formula because I need to track the actual number of different items I have on the list. I'm using Excel for Mac and don't have any addins other that what was packaged with this software. Any help is appreciated.
 

Attachments

  • Screen Shot 2023-06-22 at 10.56.24 PM.png
    Screen Shot 2023-06-22 at 10.56.24 PM.png
    22.6 KB · Views: 14

Excel Facts

Format cells as time
Select range and press Ctrl+Shift+2 to format cells as time. (Shift 2 is the @ sign).
I'm not 100% understanding exactly what you're after, but try this code on a copy of your worksheet:
VBA Code:
Sub NumberAreas()
    Dim r As Range, i As Long
    i = 1
    For Each r In Range("B1", Cells(Rows.Count, "B").End(xlUp)).SpecialCells(xlCellTypeConstants).Areas
        r.Cells(1, 1).Offset(0, -1) = i
        i = i + 1
    Next r
End Sub
 
Upvote 0
Solution
I'm not 100% understanding exactly what you're after, but try this code on a copy of your worksheet:
VBA Code:
Sub NumberAreas()
    Dim r As Range, i As Long
    i = 1
    For Each r In Range("B1", Cells(Rows.Count, "B").End(xlUp)).SpecialCells(xlCellTypeConstants).Areas
        r.Cells(1, 1).Offset(0, -1) = i
        i = i + 1
    Next r
End Sub
Thanks for the reply Kevin! I should have explained my diagram a little better. Row 1-6 is what the list currently looks like. Rows 10-15 is how I would like it to look with numbering. I tried adding this code in VBA, but I keep getting an error. Not sure if I'm supposed to change any information on this line? Sorry
 

Attachments

  • Screen Shot 2023-06-23 at 2.03.17 AM.png
    Screen Shot 2023-06-23 at 2.03.17 AM.png
    25.3 KB · Views: 6
Upvote 0
OK. With the code in post #2, my test sheet goes from this:
Book1
AB
1Apples
2
3Bananas
4Bananas
5
6Oranges
7
Sheet1


to this:
Book1
AB
11Apples
2
32Bananas
4Bananas
5
63Oranges
7
Sheet1


Is that not what you wanted?
 
Upvote 0
Kevin, you're genius! So, I copied a sample of my list to another sheet just to start over; I applied the code above, and it worked! You've saved me sooooo many hours of numbering manually!! Thank you!
 
Upvote 0
Kevin, you're genius! So, I copied a sample of my list to another sheet just to start over; I applied the code above, and it worked! You've saved me sooooo many hours of numbering manually!! Thank you!
Happy to help and welcome to the forum :)
 
Upvote 0

Forum statistics

Threads
1,223,759
Messages
6,174,336
Members
452,555
Latest member
colc007

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