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

Workdays for a market open Mon, Wed, Friday?
Yes! Use "0101011" for the weekend argument in NETWORKDAYS.INTL or WORKDAY.INTL. The 7 digits start on Monday. 1 means it is a weekend.

Forum statistics

Threads
1,223,896
Messages
6,175,263
Members
452,627
Latest member
KitkatToby

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