ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Textbox on user form type mismatch (https://www.excelbanter.com/excel-programming/381510-textbox-user-form-type-mismatch.html)

Gimp

Textbox on user form type mismatch
 
I have a textbox on a user form that is giving me an error when a
number is entered in. This number is a percent and the code for the
textbox is:

Private Sub TextBox35_AfterUpdate()
If IsNumeric(Me.TextBox35.Value) Then
Me.TextBox35.Value = Format(CDbl(TextBox35) / 100, "0.00%")
End If
End Sub

This works fine only if I enter a whole number(?), meaning, 10, 12, 30,
44 all will work. But if I enter 10.3, then I get the error. Any
thoughts on where I'm going wrong?

There is another button on the form that when clicked will mulitply
textbox1 x textbox35 + textbox1. So the flow is: 1) a value is in
textbox1, 2) I enter in a 'markup', say 10.5 and click the button. The
error comes up at that point, again, only if I use a '.'....in
textbox35.


Doug Glancy[_7_]

Textbox on user form type mismatch
 
Gimp,

The code you showed works fine when I use it. What line of code is
highlighted when you get the type mismatch error? From your description, it
sounds like the error is happening somewhere else in your code.

Doug

"Gimp" wrote in message
oups.com...
I have a textbox on a user form that is giving me an error when a
number is entered in. This number is a percent and the code for the
textbox is:

Private Sub TextBox35_AfterUpdate()
If IsNumeric(Me.TextBox35.Value) Then
Me.TextBox35.Value = Format(CDbl(TextBox35) / 100, "0.00%")
End If
End Sub

This works fine only if I enter a whole number(?), meaning, 10, 12, 30,
44 all will work. But if I enter 10.3, then I get the error. Any
thoughts on where I'm going wrong?

There is another button on the form that when clicked will mulitply
textbox1 x textbox35 + textbox1. So the flow is: 1) a value is in
textbox1, 2) I enter in a 'markup', say 10.5 and click the button. The
error comes up at that point, again, only if I use a '.'....in
textbox35.




merjet

Textbox on user form type mismatch
 
It worked for me, too. Be more specific about the error and maybe post
the line of code that produces it. Also, I did try Val("10.00%") and
Val("10.30%) in the Immediate Window. The first worked and the second
gave a type mismatch error. I don't know why. In any case, rather than
trying to do arithmetic with text variables, you might try converting
them to numbers first.

HTH,
Merjet


merjet

Textbox on user form type mismatch
 
Also, I did try Val("10.00%") and Val("10.30%) in the Immediate Window.

Oops. I meant Val("10.30%")

Merjet


Gimp

Textbox on user form type mismatch
 
Thanks for all checking into this. Yeah, I get the debug error when I
click the button and 10.5 (for example) is in textbox35..here is the
code to that button:

Private Sub CommandButton6_Click() ' The RECAL Button
If TextBox33.Value = "" And TextBox35 = "" Or TextBox32.Value = "" Then
MsgBox "In order to ReCalc: There must be a Total or A Markup OR A
Discount Entered"
'TextBox34.Value = ""
Exit Sub
Else
If TextBox33.Value < "" And TextBox35 = "" Then
TextBox34.Value = TextBox32.Value - TextBox33.Value
Else
If TextBox33.Value < "" And TextBox35.Value < "" Then
TextBox34.Value = TextBox32.Value + (Val(TextBox35.Value) / 100
* TextBox32.Value) - TextBox33.Value
Else
If TextBox33.Value = "" And TextBox35.Value "0.01" Then
ERROR ON THIS LINE TextBox34.Value = TextBox32.Value +
(Val(TextBox35.Value) / 100 * TextBox32.Value)
End If
End If
End If
End If

TextBox34.Text = Format(TextBox34.Text, "currency")
end sub

I added the comment there error on this line....of course...


merjet wrote:
Also, I did try Val("10.00%") and Val("10.30%) in the Immediate Window.


Oops. I meant Val("10.30%")

Merjet



merjet

Textbox on user form type mismatch
 

ERROR ON THIS LINE TextBox34.Value = TextBox32.Value +
(Val(TextBox35.Value) / 100 * TextBox32.Value)


I suspect Val(TextBox35.Value) is the problem, like Val("10.30%")
was for me. So maybe you should avoid doing arithmetic with text
variables, and use numbers instead.

HTH,
Merjet



All times are GMT +1. The time now is 12:12 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com