Auto generate next sequence number behind the date

Weasley0307

New Member
Joined
Dec 25, 2023
Messages
6
Office Version
  1. 2021
Platform
  1. Windows
Hi I am a beginner that just started learning vba recently. I am working on a user entry form where it will automatically generate the next reference no. in the format of YYMMDD-xxx, where xxx will starts from 001 if it is the first entry of today, so theoretically it will look something like this:

231225-001 (first entry of today)
231225-002 (second entry of today)
231226-001 (first entry of a new day)
etc..

I got the format of the date worked out, but I have absolutely no idea how to generate the sequential number behind it and how to code so that it can detect whether the new entry is the first on that current date or not.

Hope someone can help me with this. Thanks!
 

Excel Facts

Will the fill handle fill 1, 2, 3?
Yes! Type 1 in a cell. Hold down Ctrl while you drag the fill handle.
Hello

Try below code ... Assuming you're storing the data in Sheet1 from cell A2 going downward to A10000
VBA Code:
Sub test()

Dim NextSeq As Long
NextSeq = [sum(--(left('Sheet1'!A2:A10000,6)=text(today(),"yymmdd")))] + 1

MsgBox "Next sequence number is : " & NextSeq

End Sub
 
Last edited:
Upvote 0

Forum statistics

Threads
1,215,078
Messages
6,122,997
Members
449,093
Latest member
masterms

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