generate the next sequential number

kelvin_9

Active Member
Joined
Mar 6, 2015
Messages
444
Office Version
  1. 2019
Hello All,
Previously, I use this code to start record my customer inquiry daily, and now I want to amend it and easier for analysis monthly records if my superior needs. However I get stuck on sequential number generation.
VBA Code:
Sub Macro1()

Range("A1000").End(xlUp).Offset(1, 0).Select
Selection.Value = Selection.Offset(-1, 0).Value + 1

End Sub
I created a calendar in VBA at first, select the inquiry date when someone inquired, and secondly, I wonder can it be generate the next new sequential number automatic like below table.

Book1
AC
1BASIC INFORMATION
2DATE (MM-DD-YYYY)CASE #
3Apr-05-20201
4Apr-05-20202
5Apr-06-20201
6Apr-06-20202
7Apr-06-20203
8Apr-06-20204
9Apr-06-20205
10Apr-06-20206
11Apr-07-20201
12Apr-07-20202
13Apr-07-20203
14Apr-07-20204
15Apr-07-20205
16Apr-07-20206
17Apr-07-20207
18Apr-07-20208
19Apr-08-20201
20Apr-08-20202
21Apr-08-20203
22Apr-08-20204
DATABASE


remarks:
case# in column C should be using 001, 002, 003, 004...... instead of single numbers 1, 2, 3, 4
(I curious why the outcome was single. I'm sorry)

Thanks All for the great guidance.
kelvin
 

Excel Facts

Is there a shortcut key for strikethrough?
Ctrl+S is used for Save. Ctrl+5 is used for Strikethrough. Why Ctrl+5? When you use hashmarks to count |||| is 4, strike through to mean 5.
You actually do not need VBA for this. It can be done with a simple formula.
Put this in cell C3 and copy down:
=IF(A3=A2,C2+1,1)

Then, if you want it to display in "001" format, simply add a Custom Format to column C of 000.
 
Upvote 0
Thanks Joe4. It works perfectly! ;)
Can I still have this "case # text box" display the next new sequential number? like year+month+case# which is "20""04"-"001", "20""04"-"002"....

cal.jpg


Thanks & Regards,
kelvin
 
Upvote 0
Does this formula give you what you want?
=TEXT(A3,"yymm") & "-" & TEXT(C3,"000")
 
Upvote 0
Almost there. this come with "Apr-05-2020-001"

Expected format: 20APR-001, 20APR-002.........20MAY-001, 20MAY-002, 20MAY-003..... showing in "case # text box"
Expected goal: the case number is generate autonomic when one case is completed and saved. Assuming that, I'm filing a new case so I will get 001 first, after that, i will get 002 and so on.

Apology for my poor presentation.

Thanks & Regards,
kelvin
 
Upvote 0
Almost there. this come with "Apr-05-2020-001"

Expected format: 20APR-001, 20APR-002.........20MAY-001, 20MAY-002, 20MAY-003..... showing in "case # text box"
OK, I thought you said you wanted the following format:
Can I still have this "case # text box" display the next new sequential number? like year+month+case# which is "20""04"-"001", "20""04"-"002"....
If you want it to look like "20APR-001", then use:
=UPPER(TEXT(A3,"yymmm")) & "-" & TEXT(C3,"000")
 
Upvote 0
OK, I thought you said you wanted the following format:

If you want it to look like "20APR-001", then use:
=UPPER(TEXT(A3,"yymmm")) & "-" & TEXT(C3,"000")

I want "year+month-case#" ?
Book1
ACDE
1BASIC INFORMATION
2DATE (MM-DD-YYYY)CASE #
3Apr-05-2020001APR-05-2020-00120APR-001
4Apr-05-2020002APR-05-2020-00220APR-002
5Apr-06-2020001APR-06-2020-00120APR-003
6Apr-06-2020002APR-06-2020-00220APR-004
7Apr-06-2020003APR-06-2020-00320APR-005
8Apr-06-2020004APR-06-2020-00420APR-006
9Apr-06-2020005APR-06-2020-00520APR-007
10Apr-06-2020006APR-06-2020-00620APR-008
11Apr-07-2020001APR-07-2020-00120APR-009
12Apr-07-2020002APR-07-2020-00220APR-010
13Apr-07-2020003APR-07-2020-00320APR-011
14Apr-07-2020004APR-07-2020-00420APR-012
15Apr-07-2020005APR-07-2020-00520APR-013
16Apr-07-2020006APR-07-2020-00620APR-014
17Apr-07-2020007APR-07-2020-00720APR-015
18Apr-07-2020008APR-07-2020-00820APR-016
19Apr-08-2020001APR-08-2020-00120APR-017
DATABASE
Cell Formulas
RangeFormula
C3:C19C3=IF(A3=A2,C2+1,1)
D3:D19D3=UPPER(TEXT(A3,"yymmm")) & "-" & TEXT(C3,"000")


In addition, where should i put this formula and then showing in "case # text box" / how can i generate the next new number automatic?

Thanks & Regards,
kelvin
 
Upvote 0
I want "year+month-case#"
I am sorry, you are not being very clear here. That is not very helpful, as that does not show me the format you want for each piece (month can be shown in at least a half-dozen different ways).
Please show me an example of EXACTLY what you want it to look like.

how can i generate the next new number automatic
You really cannot do that ahead of time, because it depends on the date being entered, right? Until we know the data, we don't know the next number.
The formulas are dynamic, so as soon as you enter a new value in column A, the formulas in the other cells should calculate what you need.
 
Upvote 0
Sorry Joe, sorry for my poor english & presentation.

Appreciate if I could start it all over again and try to be simple. Part of the form including:
Color Tan: case#, start to filing a guest inquiry, first select the date, second generate a next new case# automatic
Color Aqua: reference#, for guest & admin usage, easy to locate/search by providing this reference#
(I.E. 20 means year, 04 or 05 means month, 000 means case#)

When I start to record an inquiry, I open-up the vba form, I select the date and I wish the case# will be populated a next one since last saved.

Book1
ACD
1BASIC INFORMATION
2DATE (MM-DD-YYYY)CASE #REFERENCE #
3Apr-05-20200012004-001
4Apr-05-20200022004-002
5Apr-06-20200032004-003
6Apr-06-20200042004-004
7Apr-06-20200052004-005
8May-01-20200012005-001
9May-01-20200022005-002
10May-02-20200032005-003
11May-03-20200042005-004
12May-03-20200052005-005
13May-03-20200062005-006
14May-04-20200072005-007
DATABASE


Thanks & Regards,
kelvin
 
Upvote 0
My first two replies (posts 2 and 4 above), give you the exact formulas you need for column C and D in your last post.

When I start to record an inquiry, I open-up the vba form, I select the date and I wish the case# will be populated a next one since last saved.
Does this form automatically choose the current date, or does the user supply the date?
Are you saying that you want the next sequence number to appear on this form right away (once date is decided)?

If the user supplies the date, it is going to need to wait for them to populate the date, and then look up on the table what the next value for that date should be.

If they are allowed to pick there own dates, what happens if they choose a date older than the last record in the table in Excel?
After writing it to Excel, do you have VBA re-sort that list?

Please post all the VBA code you have behind this form.
 
Upvote 0

Forum statistics

Threads
1,215,544
Messages
6,125,444
Members
449,226
Latest member
Zimcho

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