VBA increment number sequence based on 2 cell values

NormChart55

New Member
Joined
Feb 22, 2022
Messages
44
Office Version
  1. 2016
Platform
  1. Windows
Hello - I am in need of a macro number sequence of files so that I can separate.

I have data headers in column C4-H4 and all the data will be located in C5:H50000 depending on how much data there is (that changes). I am needing to add a number sequence in Column B that goes in increment based on C (address) and H (reference) data. Example below. In the example below, I would want the sequence for first 3 lines to be 1/1/2 because line 3 the reference changes. Lines 4/5 would be 1/2 because the 5th line reference changes. Basically if reference changes compared to the address then it should be a new number sequence for that only so I can filter out the number of separate pages. I hope that makes sense. Thanks for any and all help you can provide.

AddressDatapartQuantityvendorReference
AAAXXX
AAAXXX
AAAXXY
BBBYYY
BBBYYX
 

Excel Facts

Square and cube roots
The =SQRT(25) is a square root. For a cube root, use =125^(1/3). For a fourth root, use =625^(1/4).
Do you need a "macro" for this?
Book1
BCDEFGH
4AddressDatapartQuantityvendorReference
51AAAXXX
61AAAXXX
72AAAXXY
81BBBYYY
92BBBYYX
Sheet1
Cell Formulas
RangeFormula
B5:B9B5=IF(C5<>C4,1,IF(AND(C5=C4,H5=H4),1,B4+1))
 
Upvote 0
=IF(C5<>C4,1,IF(AND(C5=C4,H5=H4),1,B4+1))
Hello - thank you, no I was probably over thinking it. however this equation does not properly sequence as the data may not always be in order. so in this example below, it gives 3 but it should only be 2 since there is only 2 unique numbers for reference?

JGD
xxx - 1
JGD
xxx - 1
JGD
xxy - 2
JGD
xxx - 3
 
Upvote 0
Any thoughts out there how to achieve this even if the first column data is not in order?
 
Upvote 0
This can be done with a simple COUNTIFS formula. Order does not matter.
Place this in cell B5 and copy down:
Excel Formula:
=COUNTIFS(C$5:C5,C5,H$5:H5,H5)
 
Upvote 0
This can be done with a simple COUNTIFS formula. Order does not matter.
Place this in cell B5 and copy down:
Excel Formula:
=COUNTIFS(C$5:C5,C5,H$5:H5,H5)
thanks for the help. that does create a sequence, but if the data in column C and H do not change, it should not increase the sequence. The number sequence should only increase if H changes, and if column C changes the sequence starts again.
 
Upvote 0
I am not sure I understand all your various requirements.
Please post a detailed example that covers all the different scenarios, and show us your expected output.
 
Upvote 0
I am not sure I understand all your various requirements.
Please post a detailed example that covers all the different scenarios, and show us your expected output.
Below is an example data and includes the Sequence that should come up. thanks for taking a look

CodeReferenceExpected sequence
JYTXXX
1​
JYTXXX
1​
JYTXXY
2​
JGDXXX
1​
JGDXXX
1​
JGDXXY
2​
JGDXXY
2​
JGDXXX
1​
JZXXXX
1​
JZXXXX
1​
JZXXXX
1​
JYTXXX
1​
JYTXXY
2​
JYTXXZ
3​
 
Upvote 0
Yeah, that could get a bit tricky.
Any reason why the data cannot be sorted first?
Then you may be able to use one of the early solutions provided.
 
Upvote 0
I can add a sort if needed, but the other solution still seems to sequence slightly off to what I would expect. if reference changes back to one already used prior, it adds a new number and if the same one is then used going forward it goes back to 1 again. Example below is using this formula

RangeFormula
Cell Formulas
B5:B9B5=IF(C5<>C4,1,IF(AND(C5=C4,H5=H4),1,B4+1))

SequenceCODEReference
1​
JGD
XXX
1​
JGD
XXX
1​
JGD
XXX
2​
JGD
XXY
3​
JGD
XXX
1​
JGD
XXX
1​
JGD
XXX
1​
JGD
XXX
1​
JGD
XXX
1​
JGD
XXX
 
Upvote 0

Forum statistics

Threads
1,223,888
Messages
6,175,203
Members
452,617
Latest member
Narendra Babu D

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