Error 13 - Type Mismatch

tigerdel

Board Regular
Joined
Oct 13, 2015
Messages
101
Office Version
  1. 365
Platform
  1. Windows
In my UserForm I have a number TextBoxes and ComboBoxes and I am trying to get 2 TextBoxes to sum values

1601460411391.png


A – [txtQty] Quantity entered by user
B – [cmbMarkUp] Mark Up chosen by User
C – [txtPrice] Unit Price added by code
D – [txtMarkUp] Code below
E – [txtTotal] Code below

For D & E, I added the following code but get the Error 13 - Type mismatch error

Code:
Private Sub cmbMarkUp_Change()
txtMarkUp.Value = txtPrice.Value * (1 + cmbMarkUp.Value)
txtTotal.Value = txtPrice.Value * txtQty
End Sub

Any ideas??

Many thanks
 

Excel Facts

Last used cell?
Press Ctrl+End to move to what Excel thinks is the last used cell.

dmt32

Well-known Member
Joined
Jul 3, 2012
Messages
6,512
Office Version
  1. 2019
Platform
  1. Windows
Hi,
what you have in your textbox & combobox is Text - try using a type conversion function to coerce your text to the required data type & see if this resolves your issue

Rich (BB code):
Private Sub cmbMarkUp_Change()
    txtMarkUp.Value = Val(txtPrice.Value) * (1 + Val(cmbMarkUp.Value))
    txtTotal.Value = Val(txtPrice.Value) * Val(txtQty)
End Sub

The Val function stops reading the string at the first character that it is not able to recognize as part of a number or if no valid numeric value, it returns Zero.

Dave
 

mohadin

Well-known Member
Joined
Mar 22, 2015
Messages
1,091
Office Version
  1. 2013
Platform
  1. Windows
Hi
Try some thing like this
VBA Code:
TextBox3 = TextBox1 * 1 + TextBox2 * 1
 

tigerdel

Board Regular
Joined
Oct 13, 2015
Messages
101
Office Version
  1. 365
Platform
  1. Windows
Hi,
what you have in your textbox & combobox is Text - try using a type conversion function to coerce your text to the required data type & see if this resolves your issue

Rich (BB code):
Private Sub cmbMarkUp_Change()
    txtMarkUp.Value = Val(txtPrice.Value) * (1 + Val(cmbMarkUp.Value))
    txtTotal.Value = Val(txtPrice.Value) * Val(txtQty)
End Sub

The Val function stops reading the string at the first character that it is not able to recognize as part of a number or if no valid numeric value, it returns Zero.

Dave

Thanks Dave
That did kind of work except for some reason it txtMarkUp.Value has the decimal place one to the right

i.e. I added one item at 28.8 and added 10% from cmbMarkup and instead of 31,68 in txtMarkUp it shows 316.8

Any ideas??
 

dmt32

Well-known Member
Joined
Jul 3, 2012
Messages
6,512
Office Version
  1. 2019
Platform
  1. Windows
I added one item at 28.8 and added 10% from cmbMarkup and instead of 31,68 in txtMarkUp it shows 316.8

Any ideas??

try dividing cmbMarkup by 100 and see if that resolves

Rich (BB code):
txtMarkUp.Value = Val(txtPrice.Value) * (1 + Val(cmbMarkUp.Value) / 100)

Dave
 

Watch MrExcel Video

Forum statistics

Threads
1,129,528
Messages
5,636,837
Members
416,945
Latest member
Himu

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