Create an Automated document numbering

Pestomania

Active Member
Joined
May 30, 2018
Messages
332
Office Version
  1. 365
Platform
  1. Windows
I am trying to identify how to set N2 to identify the "next" available number for a document type. If you were to put Facility 10, Dept 1 in row 5, it would produce DOC-7001 as the answer. No numbers can be reused, only unique identifiers.

Please see below details, hopefully you can help me figure something out!

Using Microsoft 335 Apps for Enterprise, Version 2308 (Build 16731.20636)


BCP Document Numbering Tracker.xlsx
ABCDEFGHIJKLMNOPQ
1Site NameType of DocumentStartEnd# of ProceduresConcatenateSite Names# Start RangeDocument NumberFacility NameDepartmentSub-Title
2Facility 10Dept 170007010107000-7010Facility 17900DOC-7000Facility 10Dept 1Sub-title 1
3Facility 10Dept 270117030197011-7030Facility 2DOC-7101Facility 10Dept 12Sub-title 2
4Facility 10Dept 37031704097031-7040Facility 37200DOC-7255Facility 3Dept 5Sub-title 3
5Facility 10Dept 470417055147041-7055Facility 47300
6Facility 10Dept 57056706047056-7060Facility 57400
7Facility 10Dept 67061706547061-7065Facility 67500
8Facility 10Dept 77066707047066-7070Facility 77600
9Facility 10Dept 87071707547071-7075Facility 87700I want to set up Document Number to be automated to use the "Facility Name" and "Dept" to identify the next document number available based on the ranges in the blue table.
10Facility 10Dept 97076708047076-7080Facility 97800
11Facility 10Dept 107081708547081-7085Facility 107000
12Facility 10Dept 1170867100147086-7100Facility 11
13Facility 10Dept 127101710547101-7105
14Facility 10Dept 137106711047106-7110
15Facility 10Dept 147111711547111-7115
16Facility 10Dept 157116712047116-7120
17Facility 10Dept 167121713097121-7130
18Facility 10Dept 1771317145147131-7145
19Facility 10Dept 187146715047146-7150
20Facility 10Dept 197151715547151-7155
21Facility 3Dept 172007210107200-7210
22Facility 3Dept 27211721657211-7216
23Facility 3Dept 37217722697217-7226
24Facility 3Dept 472277247207227-7247
25Facility 3Dept 572487264167248-7264
26Facility 3Dept 672657286217265-7286
27Facility 3Dept 772877297107287-7297
Data Tables
Cell Formulas
RangeFormula
C3:C20,C22:C27C3=D2+1
D2:D27D2=[@Start]+[@['# of Procedures]]
F2:F27F2=C2&"-"&D2
Cells with Data Validation
CellAllowCriteria
A2:A27List=Site_Names
O2:O4List=Site_Names
 

Excel Facts

What is the fastest way to copy a formula?
If A2:A50000 contain data. Enter a formula in B2. Select B2. Double-click the Fill Handle and Excel will shoot the formula down to B50000.
I am not sure whether the following is what you want but you can give it a try in N5 (it should fill the value once you enter facility name and department):

=LET(a,MAX(--(RIGHT(FILTER(N$2:N4,(O$2:O4=O5)*(P$2:P4=P5)),4))),b,XLOOKUP(O5&P5,$A$2:$A$27&$B$2:$B$27,$D$2:$D$27),c,XLOOKUP(O5&P5,$A$2:$A$27&$B$2:$B$27,$C$2:$C$27),IFERROR(IFS(a<b,"DOC-"&a+1,a=b,0),"DOC-"&c))
 
Upvote 0
I am not sure whether the following is what you want but you can give it a try in N5 (it should fill the value once you enter facility name and department):

=LET(a,MAX(--(RIGHT(FILTER(N$2:N4,(O$2:O4=O5)*(P$2:P4=P5)),4))),b,XLOOKUP(O5&P5,$A$2:$A$27&$B$2:$B$27,$D$2:$D$27),c,XLOOKUP(O5&P5,$A$2:$A$27&$B$2:$B$27,$C$2:$C$27),IFERROR(IFS(a<b,"DOC-"&a+1,a=b,0),"DOC-"&c))
This worked phenomenally for everything except in N2. Since i am hoping to make this a table, if I was able to overwrite cells in that column, that would be awesome!

I am unsure if there is a way to "lock" in a document number or if that would be better suited in Microsoft Access. Now that i am thinking about it, that may be my better option for maintaining a table.
 
Upvote 0
Ah, of course I forgot about the 1st occurence. Try to place the following madness into N2:

="DOC-"&LET(b,XLOOKUP(O2&P2,$A$2:$A$27&$B$2:$B$27,$C$2:$C$27),c,XLOOKUP(O2&P2,$A$2:$A$27&$B$2:$B$27,$D$2:$D$27),IFERROR(IF(ROW()=2,b,IF(AND(ROW()<>2,MAX(--(RIGHT(FILTER(N$1:N1,(O$1:O1=O2)*(P$1:P1=P2)),4)))<c),MAX(--(RIGHT(FILTER(N$1:N1,(O$1:O1=O2)*(P$1:P1=P2)),4)))+1,"NN")),XLOOKUP(O2&P2,$A$2:$A$27&$B$2:$B$27,$C$2:$C$27)))
 
Upvote 0
Solution
Ah, of course I forgot about the 1st occurence. Try to place the following madness into N2:

="DOC-"&LET(b,XLOOKUP(O2&P2,$A$2:$A$27&$B$2:$B$27,$C$2:$C$27),c,XLOOKUP(O2&P2,$A$2:$A$27&$B$2:$B$27,$D$2:$D$27),IFERROR(IF(ROW()=2,b,IF(AND(ROW()<>2,MAX(--(RIGHT(FILTER(N$1:N1,(O$1:O1=O2)*(P$1:P1=P2)),4)))<c),MAX(--(RIGHT(FILTER(N$1:N1,(O$1:O1=O2)*(P$1:P1=P2)),4)))+1,"NN")),XLOOKUP(O2&P2,$A$2:$A$27&$B$2:$B$27,$C$2:$C$27)))
Awesome!!! That works!
 
Upvote 0
That is good to hear. Just note that at the moment the formula is constructed that it relies on the first calculation being in the 2nd row (cf. the ROW()=2/ROW()<>2 part), and it returns DOC-NN when there are more procedures than allowed (I am not sure whether this could happen).
 
Upvote 0

Forum statistics

Threads
1,223,909
Messages
6,175,314
Members
452,634
Latest member
cpostell

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