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

Select all contiguous cells
Pressing Ctrl+* (asterisk) will select the "current region" - all contiguous cells in all directions.

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
68,339
Office Version
  1. 365
Platform
  1. Windows
How about
VBA Code:
Cells(erow, 1) = Val(Label1)
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
68,339
Office Version
  1. 365
Platform
  1. Windows
You're welcome & thanks for the feedback.
 
Master Excel Bundle

Excel contains over 450 functions, with more added every year. That’s a huge number, so where should you start? Right here with this bundle.

Forum statistics

Threads
1,152,569
Messages
5,770,907
Members
425,651
Latest member
Mark Cashin

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
Top