VBA Code to Auto Populate Text Box with Sequential Record #

Parebody

New Member
Joined
Jan 4, 2018
Messages
43
Office Version
  1. 2016
Platform
  1. Windows
I am setting up a form for my excel spreadsheet. When I click on my form button, I want the first text box in my form to auto populate with the next available record # from my spreadsheet. My record # format is as follows: FP000001, FP000002, FP000003, etc... Any suggestions on how to write the code to auto populate the record # text box when the form is opened? I'm getting hung up on the format of the record # (letters & numbers).

1593035842370.png
 

Excel Facts

Round to nearest half hour?
Use =MROUND(A2,"0:30") to round to nearest half hour. Use =CEILING(A2,"0:30") to round to next half hour.
How about this? You may need to change 'Me.TextBox1' to the name of your record # textbox.

VBA Code:
Private Sub UserForm_Activate()
Me.TextBox1.Text = "FP" & Format(Replace(Range("A" & Rows.Count).End(xlUp).Text, "FP", "") + 1, "000000")
End Sub
 
Upvote 0
If in cell A1 you have the header, and the first value will be in cell A2, try the following code, it even works for the first record.

VBA Code:
Private Sub UserForm_Activate()
  TextBox1.Value = "FP" & Format(Range("A" & Rows.Count).End(3).Row, "000000")
End Sub
 
Upvote 0
That worked perfectly! And now I have better insight on how to combine text and numbers for formatting. Thanks again!
 
Upvote 0

Forum statistics

Threads
1,214,587
Messages
6,120,405
Members
448,958
Latest member
Hat4Life

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