Next available number in column

Ana_P

New Member
Joined
Aug 22, 2019
Messages
35
Office Version
  1. 2016
Platform
  1. Windows
Hi,

I have an excel s/sheet with order numbers in one column that I would like to prefill based on the next available number in that column.

A few things to note:
- the numbering is a 5 digit number with the first 2 digits being the year the order is in (i.e. 22) followed by 001, 002 etc
- if an order contains multiple items it will use the same order number therefore the next available number will be overridden to accommodate this
- I need the formula to keep working in subsequent rows even if the previous row was overridden per above point
- the data set is in a table
- the numbers aren't in order in the table as the table is sorted by different columns at different times

Any help would be greatly appreciated.

Thanks
 
If you want the numbers to remain the same even when the data is sorted differently then that may not be possible with a formula approach. However, that may depend on just what information that you have in your table. Would need to see some of that - all columns- (with any sensitive data disguised) to help decide.
Yes, the number must not change if the data is sorted differently. You will notice some numbers are missing in the sequence - this is because an order was placed then cancelled at some point and in that case the row/s are deleted.

So, to reiterate, the first order of each new year will start with year followed by 000, 001 etc. Multiple items per order require the same order number (but entered on different rows in Excel), and deleted orders will result in missing numbers, but I'm assuming that's not an issue. I require the next available number to prefill when entering a new order, with the possibility of overriding that number if the customer orders multiple items in one order on the same date.

Hope that makes sense.

Sample.xlsx
ABCDEFGHIJKLMN
1Date RaisedDate DeliveredF/YCWOFinisherAdd LTCustomerCustomer POCommentsDue DateRevised ETASchedule DateSchedule WeekDate Received
9318/01/2218/01/22F22000ABGHI1/02/221/02/22525/01/22
9418/01/2218/01/22F22001ABPQR1/02/221/02/2253/02/22
9518/01/2218/01/22F22001ABPQR1/02/221/02/2253/02/22
9618/01/2218/01/22F22001ABPQR1/02/221/02/2253/02/22
9718/01/2218/01/22F22004ABPQR1/02/221/02/2253/02/22
9818/01/2218/01/22F22005ABAZ1/02/221/02/22516/02/22
9918/01/2218/01/22F22008ABGHI1/02/221/02/22531/01/22
10018/01/2218/01/22F22008ABGHI1/02/221/02/22531/01/22
10118/01/2218/01/22F22008ABGHI1/02/221/02/22531/01/22
10218/01/2218/01/22F22008ABGHI1/02/221/02/22531/01/22
10318/01/2218/01/22F22009ABABC1/02/221/02/2251/02/22
10418/01/2218/01/22F22009ABABC1/02/221/02/2251/02/22
10519/01/2219/01/22F22011ABOP82/02/222/02/22511/02/22
10620/01/2224/01/22F22012ABJKL7/02/227/02/22617/02/22
10720/01/2224/01/22F22012ABJKL7/02/227/02/22617/02/22
10820/01/2231/01/22F22012ABJKL14/02/2214/02/22725/02/22
10929/03/2229/03/22F22012ABJKL12/04/2212/04/221514/04/22
11020/01/222/02/22F22013ABJKL16/02/2216/02/22725/02/22
11120/01/2221/01/22F22014ABJKL4/02/224/02/22530/05/22
11220/01/2229/03/22F22014ABJKL12/04/2212/04/221512/04/22
11320/01/2219/01/22F22015ABJKL2/02/222/02/22510/02/22
11420/01/2231/01/22F22016ABYZ14/02/2214/02/2274/02/22
11520/01/2231/01/22F22016ABYZ14/02/2214/02/22717/02/22
11625/01/2225/01/22F22018ABGHI8/02/228/02/22628/01/22
11725/01/2225/01/22F22018ABGHI8/02/228/02/22628/01/22
11825/01/2225/01/22F22018ABGHI8/02/228/02/2261/02/22
11925/01/2225/01/22F22018ABGHI8/02/228/02/22614/02/22
12025/01/2225/01/22F22018ABGHI8/02/228/02/22614/02/22
12125/01/2225/01/22F22019ABAZ8/02/228/02/22616/02/22
12225/01/2225/01/22F22020ABPQR8/02/228/02/2263/02/22
12325/01/2225/01/22F22021CDGHI8/02/228/02/2264/02/22
12425/01/2225/01/22F22021CDGHI8/02/228/02/2264/02/22
12525/01/2225/01/22F22021CDGHI8/02/228/02/2264/02/22
12625/01/2225/01/22B22022CDBY22/03/2222/03/221217/02/22
July-Dec 2022
Cell Formulas
RangeFormula
L93:L126L93=IF(ISBLANK([@[Revised ETA]]),[@[Due Date]],[@[Revised ETA]])
M93:M126M93=IF(OR([@[Schedule Date]]="",[@[Schedule Date]]="Missing Info"),"",ISOWEEKNUM([@[Schedule Date]]))
J93:J126J93=IF(ISBLANK([@[Date Raised]]),"",IF(OR(ISBLANK([@[Date Delivered]]),ISBLANK([@[F/Y]])),"Missing Info",[@[Date Delivered]]+VLOOKUP([@[F/Y]],Lead_Time,3,FALSE)+[@[Add LT]]))
Cells with Conditional Formatting
CellConditionCell FormatStop If True
I2:I601Expression=AND($Q2="Open",ISNUMBER(SEARCH("ASAP",$I2)))textNO
I2:I601Expression=AND($Q2="Open",ISNUMBER(SEARCH("Urgent",$I2)))textNO
I2:I601Expression=AND($Q2="Open",ISNUMBER(SEARCH("Repro",$I2)))textNO
L2:M601Expression=AND($Q2="Open",$M2<Current_Week)textNO
J2:J601Expression=ISNUMBER($K2)textNO
Cells with Data Validation
CellAllowCriteria
J2:L126Date>1/01/1900
N2:N126Date>1/01/1900
A2:B601Date>1/01/1900
C2:C601List=Reference!$A$3:$A$7
E2:E601List=Reference!$A$15:$A$17
F2:F601Whole numberbetween 0 and 99
 
Upvote 0

Excel Facts

When did Power Query debut in Excel?
Although it was an add-in in Excel 2010 & Excel 2013, Power Query became a part of Excel in 2016, in Data, Get & Transform Data.
Yes, the number must not change if the data is sorted differently. You will notice some numbers are missing in the sequence - this is because an order was placed then cancelled at some point and in that case the row/s are deleted.
Ok, since you mentioned deleting rows then what I thought may have been feasible by formula in fact isn't.
I think that you would need to
  1. Use macros for this task.
  2. Keep a permanent log somewhere of order numbers used. After all, if the most recent order number is 22345 and then that order is cancelled & the row(s) deleted, I presume you would want the next order number to be 22346. Without that permanent record there would be no way of knowing that 22345 had already been used (& deleted) and is therefore not available for this next order.
 
Upvote 0
Ok, since you mentioned deleting rows then what I thought may have been feasible by formula in fact isn't.
I think that you would need to
  1. Use macros for this task.
  2. Keep a permanent log somewhere of order numbers used. After all, if the most recent order number is 22345 and then that order is cancelled & the row(s) deleted, I presume you would want the next order number to be 22346. Without that permanent record there would be no way of knowing that 22345 had already been used (& deleted) and is therefore not available for this next order.
There would, more likely than not, be another order added before one is deleted. And even if it did happen the way you suggested, then there would be no need for 22345 to not be used, i.e it could be available for the next order.
 
Upvote 0
Does that mean that any order number can be re-used if it gets deleted?
Example 22001, 22002 and 22003 are used and then 22002 gets deleted can it get used again?
 
Upvote 0
No, the next number would always be the next available number after the largest number used in the list.
 
Upvote 0
1. Well, I think that you are going to need a macro to produce the CWO numbers. Is that acceptable?

2. Is it safe to assume that a customer will not have two different orders raised on the same date?
 
Upvote 0
1. Well, I think that you are going to need a macro to produce the CWO numbers. Is that acceptable?

2. Is it safe to assume that a customer will not have two different orders raised on the same date?
1. I'd prefer to use a formula over a macro.

2. Yes, I'd say so.

I have managed to come up with the following array formula to achieve what I initially wanted:

=TEXT([@[Date Raised]],"YY")&TEXT(MIN(IF(ISERROR(MATCH(TEXT([@[Date Raised]],"YY")&TEXT(ROW($1:$9999),"000"),D$2:D601,0)),ROW($1:$9999),10000)),"000")

However, I have just been advised that old "completed" orders will be deleted from the sheet and therefore I need the next available number after the largest one used (rather than the next available "unused" number. Any chance you can help me edit my formula to meet this new requirement?

Thanks
 
Upvote 0
I have managed to come up with the following array formula to achieve what I initially wanted:
Can you post a small sample table with XL2BB with that formula in use?
 
Upvote 0
Can you post a small sample table with XL2BB with that formula in use?
I have deleted XL2BB from my computer as it was causing Excel to freeze every time I saved my document and the only way I could work around it was to push the power button to turn of my laptop.

I copied the CWO column to another sheet and then entered the formula and made the column a calculated column, then copied the initial CWO values back into the worksheet and made sure they were formatted as text, and those values are the exception to the calculated column.
 
Upvote 0
I copied the CWO column to another sheet and then entered the formula and made the column a calculated column, then copied the initial CWO values back into the worksheet and made sure they were formatted as text, and those values are the exception to the calculated column.
I'm afraid that I can't reliably replicate that.
 
Upvote 0

Forum statistics

Threads
1,215,659
Messages
6,126,071
Members
449,286
Latest member
Lantern

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