How to save Label value as a Number instead of Text

Yoshi1989

New Member
Joined
Aug 2, 2021
Messages
3
Office Version
  1. 365
Platform
  1. Windows
Hi,

Just trying to work out how to convert a label which is setup to automatically increment each time Userform is loaded, to save as a Number.

The auto increment is working, but when pressing Submit on the Userform it is saving as Text instead of a Number, and unless I manually convert this to a number it stops auto incrementing.

Private Sub cmdNewHire_Click()
Dim erow As Long
erow = Sheet1.Cells(Rows.Count, 1).End(xlUp).Offset(1, 0).Row
Cells(erow, 1) = Label1
Cells(erow, 2) = txtHireDate
Cells(erow, 3) = txtCustomerName
Cells(erow, 4) = txtEmail
Cells(erow, 5) = txtMobile
Cells(erow, 6) = txtLicence
Cells(erow, 7) = txtExpiry
Cells(erow, 8) = cmbHireType
Cells(erow, 9) = cmbLength
Cells(erow, 10) = cmbAccessories
Cells(erow, 11) = cmbBond
Cells(erow, 12) = txtAddress
Cells(erow, 13) = txtSuburb
Cells(erow, 14) = txtPostcode
Cells(erow, 15) = cmbState
Cells(erow, 16) = cmbStatus
Cells(erow, 17) = cmbStore

Label1 = Format(Label1.Caption, "")

End Sub



Private Sub UserForm_Initialize()

Dim x As Long
With Sheets("Sheet1")
x = Application.Max(.Columns("a"))
x = Application.Max(0, x) + 1
End With
Me.Label1.Caption = x
 

Excel Facts

Save Often
If you start asking yourself if now is a good time to save your Excel workbook, the answer is Yes
How about
VBA Code:
Cells(erow, 1) = Val(Label1)
 
Upvote 0
You're welcome & thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,214,613
Messages
6,120,515
Members
448,968
Latest member
Ajax40

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