Vba to generate Reference Number, input box for user to enter 1st Ref
Hi, i have a data sheet where Column A is the Type, basically there are 3 type. A B C.
My ref is like this "A20180601" where A is the brand, 201806 is yyyymm and 01 is the number of A.
Upon clicking a button, I hope to have a inputbox where user can enter the yyyymm and the reference will automatically generate.
However, the code will prompt a input box, example "Please input the first number for Type A/B/C", when it hit the 1st A/B/C while going down the loop.
After which, it will continue to generate the Refenence number Until it reach another 1st A/B/C where it will prompt again
I need the 1st number to be manually input becoz the whole data does not come from 1 excel file and hence the 1st reference number might not be 1.
Re: Vba to generate Reference Number, input box for user to enter 1st Ref
You refer to try
PHP Code:
Option Explicit Public Const fYear As Long = 1950 Public Const eYear As Long = 2028 Sub pInput() Dim Rng_Data As Range, tDate As String, eRng As Range Dim N As Long, I As Long, Arr(), Txt As String On Error GoTo Thoat Set Rng_Data = Application.InputBox(Prompt:="Select data ", Title:="Select the data area", Type:=8) tDate = Application.InputBox(Prompt:="Type dd/mm/yyyy ", Title:="Select dates", Type:=2) If IsDate(tDate) = False Then MsgBox "Type: dd/mm/yy hoac dd-mm-yy", vbExclamation End If If Format(tDate, "yyyy") < fYear Or Format(tDate, "yyyy") > eYear Then MsgBox "No this year", vbExclamation End If If IsDate(tDate) = True Then Txt = Format(tDate, "yyyy") & Format(tDate, "mm") End If If Rng_Data.Columns.Count = 1 Then ReDim Arr(1 To Rng_Data.Rows.Count, 1 To 1) For I = 1 To Rng_Data.Rows.Count N = Application.CountIf(Range(Rng_Data(1), Rng_Data(I)), Rng_Data(I)) Arr(I, 1) = Rng_Data(I) & Txt & Format(N, "0#") Next I End If Set eRng = Application.InputBox(Prompt:="Select a cell ", Title:="Output data", Type:=8) eRng.Resize(I - 1) = Arr Thoat: End Sub
Bookmarks