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:


[TABLE="class: grid, width: 500"]
<tbody>[TR]
[TD]A
[/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]A
[/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]A
[/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]A
[/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]B
[/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]B
[/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]B
[/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]C
[/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]C
[/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]D
[/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]D
[/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]D
[/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]D
[/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]D
[/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]D
[/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]D
[/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]E
[/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]E
[/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]F
[/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]F
[/TD]
[TD][/TD]
[TD][/TD]
[/TR]
</tbody>[/TABLE]


And here's what I need using VBA:

[TABLE="class: grid, width: 500"]
<tbody>[TR]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IF(A2,B2,"MD")&" days"
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,224,823
Messages
6,181,173
Members
453,021
Latest member
Justyna P

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