UserForm - convert percentage back to decimal. Run-time error '13' Type Mismatch

JayMess

New Member
Joined
Jul 10, 2012
Messages
12
I have a user form to simply calculate the future value of a payment series.
One text box allows the user to specify the interest rate as a percentage. Upon exit, I am able to format the value as a percent.

Code:
Private Sub TB_interest_Exit(ByVal Cancel As MSForms.ReturnBoolean)
    TB_interest.Value = Format(TB_interest.Value, "percent")
    
End Sub

In my main sub, I am trying to assign the value of the text box to a variable as a decimal.

Code:
Private Sub CB_ok_Click()
Dim payment As Single
Dim time As Integer
Dim interest As Single

    payment = TB_payment.Value
    time = TB_time.Value
    interest = Val(TB_interest.Value) / 100
End Sub

The line assigning a value to the variable interest is triggering the run-time error '13' Type Mismatch.

I want the user to see percent formatting in the text box, but I want to be able to use the value as a decimal for calculation purposes.

I am using Excel 2010 and Windows 7.

Thanks for your help!

Jay
 

Excel Facts

What is the shortcut key for Format Selection?
Ctrl+1 (the number one) will open the Format dialog for whatever is selected.
Try

Code:
interest = Val(Replace(TB_interest.Value, "%", "")) / 100
 
Upvote 0
Do you need the % sign in the textbox?

Could you not add a small label to it's <s>left</s> right for the symbol?

Then you should have no problem converting text to number.
 
Upvote 0

Forum statistics

Threads
1,203,470
Messages
6,055,604
Members
444,803
Latest member
retrorocket129

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