How to generate unique batch code which stays the same after adding and deleting new rows

bsnow

New Member
Joined
Mar 29, 2022
Messages
10
Office Version
  1. 365
Platform
  1. Windows
Hi all

I'm trying to come up with a formula or VBA code that will allow me to generate a unique new batch code once the 'Product' (in column A) has been selected and today's date has automatically populated (column B).

I already have the formula for populate today's date once a product is selected, however I need a formula that will generate a unique new 6 digit batch code in column D based on the date: MMYY followed by a sequential 2 digit next available number (i.e. 01, 02 etc.)

Example: the 1st batch made on April 1st 2022 would be 042201, next batch would be 042202, and the last 2 digits would revert back to 01 when the month changes.

Once the batch code is generated, it cannot change in that row when I then subsequent new row or delete rows.

Thanks in advance guys (y)
 

Attachments

  • Excel.JPG
    Excel.JPG
    104.6 KB · Views: 140

Excel Facts

What do {} around a formula in the formula bar mean?
{Formula} means the formula was entered using Ctrl+Shift+Enter signifying an old-style array formula.
Map1
ABCDEFG
1productDOMGeneratedBatchcodenext batchnumber220393
2220392
3211298
4220312
5
Blad1
Cell Formulas
RangeFormula
G1G1=MAX(TEXT(TODAY(),"jjmm")*100,MAX((LEFT(Tabel1[Batchcode],4)=TEXT(TODAY(),"jjmm"))*Tabel1[Batchcode]))+1
 
Upvote 0
Hi BSALV

Thanks for your help on this. I have replicated your formula and tweaked the way the date shows, but I'm struggling to show the batch code in column D.

Batch Generation.xlsm
D
2
Sheet1
 
Upvote 0
Batch Generation.xlsm
ABCDEFGH
1ProductDOMGeneratedBatchnext batch number220301
2QQQ30-Mar-22MW
3
4
5
6
7
Sheet1
Cell Formulas
RangeFormula
G1G1=MAX(TEXT(TODAY(),"YMM")*100,MAX((LEFT(Table1[Batch],4)=TEXT(TODAY(),"YMM"))*Table1[Batch]))+1
B2B2=IF(A2<>"",IF(B2<>"",B2,NOW()),"")
Cells with Data Validation
CellAllowCriteria
A2List=Sheet2!$A$1:$A$5
C2List=Sheet2!$B$1:$B$3
 
Upvote 0
i can't give you a formula in D2, otherwise it creates a circular reference.
You have to enter that number, as a constant, manually or with the help of VBA (by a button, doubleclicking, an event, ...).
 
Upvote 0

Forum statistics

Threads
1,223,907
Messages
6,175,300
Members
452,633
Latest member
DougMo

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