Not even sure where to start with this

logandiana

Board Regular
Joined
Feb 21, 2017
Messages
107
I've used VBA before for something similar, but that was when I had some helper tables. Not sure where to begin with this one.
Basically for each range, I need to assign a sequential number to the range, and then I need to assign a sequential number to each row within the range.

Here's what I've got:


A
A
A
A
B
B
B
C
C
D
D
D
D
D
D
D
E
E
F
F

<tbody>
</tbody>


And here's what I need using VBA:

A
1
1
A
1
2
A
1
3
A
1
4
B
2
1
B
2
2
B
2
3
C
3
1
C
3
2
D
4
1
D
4
2
D
4
3
D
4
4
D
4
5
D
4
6
D
4
7
E
5
1
E
5
2
F
6
1
F
6
2

<tbody>
</tbody>
 

Excel Facts

Enter current date or time
Ctrl+: enters current time. Ctrl+; enters current date. Use Ctrl+: Ctrl+; Enter for current date & time.
You can do what you want with formula. Assuming your data starts in cell A1, 1 in cell B1 and C1 and then put these formulas in the indicated cells and copy them down to the end of your data...

B2: =IF(A1=A2,B1,B1+1)

C2: =IF(A1=A2,C1+1,1)
 
Upvote 0
You can do what you want with formula. Assuming your data starts in cell A1, 1 in cell B1 and C1 and then put these formulas in the indicated cells and copy them down to the end of your data...

B2: =IF(A1=A2,B1,B1+1)

C2: =IF(A1=A2,C1+1,1)
If you must have a VBA solution, then give this macro a try...
Code:
[table="width: 500"]
[tr]
	[td]Sub SpecialNumbering()
  Dim R As Long, LastRow As Long
  Application.ScreenUpdating = False
  LastRow = Cells(Rows.Count, "A").End(xlUp).Row
  Range("B1:C1").Value = 1
  Range("B2:B" & LastRow).Formula = "=IF(A1=A2,B1,B1+1)"
  Range("C2:C" & LastRow).Formula = "=IF(A1=A2,C1+1,1)"
  Range("B2:C" & LastRow).Value = Range("B2:C" & LastRow).Value
  Application.ScreenUpdating = True
End Sub[/td]
[/tr]
[/table]
 
Upvote 0
I had been thinking of a completely different approach, but this simple formula did what I needed.
Then I incorporated it into the VBA almost identically to what you have before I even refreshed to see your second post!
Thanks for the help
 
Upvote 0

Forum statistics

Threads
1,215,681
Messages
6,126,194
Members
449,298
Latest member
Jest

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