Textbox as Integer

Vin90

New Member
Joined
Oct 20, 2017
Messages
29
Hi, I'm looking for a way to convert the textbox value so that if I put for example 5 in the textbox it will appear as 5% in the cell.

I wrote the code in this way:
Code:
Private Sub UserForm_Initialize() 
TextBox6.Value = Format(Me.TextBox6.Value / 100, "Percent")
TextBox8.Value = Format(Me.TextBox8.Value / 100, "Percent")
TextBox10.Value = Format(Me.TextBox10.Value / 100, "Percent")
End Sub
[U]​_________________________________________________________[/U]
Private Sub cmdAdd_Click()
If MsgBox("Do you want to input the data?", vbYesNo) = vbYes Then
    Dim lrow As Long
    Dim ws As Worksheet
    Set ws = Worksheets("RawData")
    lrow = ws.Cells(Rows.Count, 1).End(xlUp).Offset(1, 0).Row
    With ws[INDENT].Cells(lrow, 13).Value = Me.TextBox6.Value
.Cells(lrow, 15).Value = Me.TextBox8.Value
.Cells(lrow, 17).Value = Me.TextBox10.Value[/INDENT]
    End With
[INDENT]Me.TextBox6.Value = ""
Me.TextBox8.Value = ""
Me.TextBox10.Value = ""[/INDENT]
Else
End If
End Sub

But I kept getting a Type mismatch error, and after going through google, I think I have to make the TextBox6, 8, and 10 to Integer so that the = Formatting code can work.

Can anybody point out what's wrong and correct my code?? I tried many things, but kept getting error every time.
Cheers,
 

Excel Facts

Who is Mr Spreadsheet?
Author John Walkenbach was Mr Spreadsheet until his retirement in June 2019.

Forum statistics

Threads
1,224,822
Messages
6,181,164
Members
453,021
Latest member
Justyna P

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