Userform Incrementing Letter and Number Combinations in Sequence

Nobu

New Member
Joined
Mar 7, 2021
Messages
2
Office Version
  1. 365
Platform
  1. Windows
Hello!

I created UserForm for tracking purchases, in the Userform there is a combo box for selecting the type of purchase, 'DEBIT or CREDIT.

After selecting the purchase type there is a label box next to it that auto generates 'D0001' and 'C0001' before submitting.

The purchase numbers are going into column B and I want the form to pretty much look back at the sheet and add the next sequence numbers without any Duplicating.
Example:
D0001
C0001
D0002
D0003
C0002


This is the code I have now.

Sub FindNextPurchNum()
Dim Lastrow As Long
Dim ws As Worksheet
Set ws = Worksheets("Manager")

myName = UCase(Left(Me.CmbobxPay, 1))
myNum = Format(myNum + 1, "0000")

Lastrow = Application.WorksheetFunction.Max(Sheet3.UsedRange.Columns(2))

Me.Lbl1 = myName & myNum

End Sub
 

Excel Facts

Which Excel functions can ignore hidden rows?
The SUBTOTAL and AGGREGATE functions ignore hidden rows. AGGREGATE can also exclude error cells and more.
Hi
welcome to forum

Try this update to your code & see if does what you want

VBA Code:
Sub FindNextPurchNum()
    Dim NextPO      As Long
    Dim ws          As Worksheet
    Dim myName      As String
   
    Set ws = Worksheets("Manager")
   
    myName = UCase(Left(Me.CmbobxPay, 1))
   
    NextPO = Application.CountIf(ws.Columns(2), myName & "*") + 1
   
    Me.Lbl1 = myName & Format(NextPO, "0000")
   
End Sub

Dave
 
Upvote 0
Hi
welcome to forum

Try this update to your code & see if does what you want

VBA Code:
Sub FindNextPurchNum()
    Dim NextPO      As Long
    Dim ws          As Worksheet
    Dim myName      As String
  
    Set ws = Worksheets("Manager")
  
    myName = UCase(Left(Me.CmbobxPay, 1))
  
    NextPO = Application.CountIf(ws.Columns(2), myName & "*") + 1
  
    Me.Lbl1 = myName & Format(NextPO, "0000")
  
End Sub

Dave
Thank you Dave! It worked great!
 
Upvote 0

Forum statistics

Threads
1,214,924
Messages
6,122,294
Members
449,077
Latest member
Rkmenon

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