Sequence by group or batch

Pints

New Member
Joined
May 29, 2020
Messages
3
Office Version
  1. 365
  2. 2019
  3. 2016
  4. 2013
Platform
  1. Windows
Hi
Long time reader, first time poster.

In a journal template, a user can enter any number c. 350 predefined 4 digit codes. Each code has to be used at least twice (such is the nature of balancing journals). For each code that the user selects, I need the template to produce a new, sequential, batch ID.
For example, code 1234 might be used 5 times and each of those should use the ID 01. For code 4321, the ID used would need to use ID 02. For another code, ID 03 would be used.

There's no specific requirement that the codes are grouped together by the user (e.g. the list could be 1234, 1234, 4321, 1234)

How can I use either a formula or VBA to produce a sequential ID for each "batch" of codes? e.g. 1234 = 01, 4321 = 02, etc.

P.S. The ID produced will ultimately be used when populating an output file with VBA for loading to the accounting package.
P.P.S. If it makes any difference, not all users will be using Office 365 when populating the template.

Thanks,
Pints
 

Excel Facts

What is =ROMAN(40) in Excel?
The Roman numeral for 40 is XL. Bill "MrExcel" Jelen's 40th book was called MrExcel XL.
Welcome to the forum!

How about:

Book1
AB
1CodeID
212341
312341
443212
512341
643212
723453
834564
923453
1012341
1143212
1234564
1355555
1455555
15#N/A
Sheet10
Cell Formulas
RangeFormula
B2:B15B2=IF(COUNTIF(A$2:A2,A2)=1,MAX(B$1:B1)+1,INDEX(B$2:B2,MATCH(A2,A$2:A2,0)))


If you don't want #N/A to show up, we can add an IFERROR:

=IFERROR(IF(COUNTIF(A$2:A2,A2)=1,MAX(B$1:B1)+1,INDEX(B$2:B2,MATCH(A2,A$2:A2,0))),"")

although that's not available in older versions of Excel. If you want the ID number to have preceding zeros, you can use TEXT or use a custom format on those cells.
 
Upvote 0
By jove, I think you've got it! Thanks.
 
Upvote 0
Re. the preceding zeroes, I'll add that formatting into the VBA for when it creates the output file.
 
Upvote 0

Forum statistics

Threads
1,214,980
Messages
6,122,563
Members
449,088
Latest member
Motoracer88

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