Getting leading zeroes from a cell

Phillip2

Board Regular
Joined
Aug 5, 2019
Messages
79
Office Version
  1. 365
Platform
  1. Windows
I have a userform that I'm able to search a database that I have inside a worksheet or add a new record to the worksheet.

When searching or saving data to the worksheet it uses a three digit record number with leading zeroes. (Example 001)
However, when get a new record number it returns the number without leading zeros.

I need some assistance tweaking this so that it will include the leading zero.

Thanks

Private Sub newRecord_Click()
Dim lastCell As Range
Set lastCell = Worksheets("Data").Cells(Rows.Count, "A").End(xlUp)
TBrecord = lastCell.Value + 1

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.
How about
VBA Code:
TBrecord = Format(lastCell.Value + 1, "000")
 
Upvote 0
You're welcome & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,215,480
Messages
6,125,049
Members
449,206
Latest member
Healthydogs

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