Multiplying text box values - correct syntax

insomniac53

Board Regular
Joined
Sep 3, 2013
Messages
104
I'm trying 'simply' to multiply the contents of two text boxes and put the product in a third. This is the code I'm using:
Code:
Me.Controls.Item("TxtBox_A_Deposit").Value = format(CDbl(Me.Controls.Item("TxtBox_A_Percent").Value) * CInt(Me.Controls.Item("TxtBox_AB_Qty").Value), "£0")
but it throws up a Type Mismatch error, even though I'm forcing the data types to fit.
Can anyone tell me what I'm doing wrong?
Thanks.
 

Excel Facts

Quick Sum
Select a range of cells. The total appears in bottom right of Excel screen. Right-click total to add Max, Min, Count, Average.

mikerickson

MrExcel MVP
Joined
Jan 15, 2007
Messages
24,220
A textbox's value is a string, not a number. although your code looks like it takes that into account. Do the Percent and Qty textboxes also force units.
(i.e. put a pound sign or a percent sign in the cell).

try
Code:
Me.TxtBox_A_Deposit.Text = Format(Val(Me.TxtBox_A_Percent.Text) * Val(Me.TxtBox_AB_Qty.Text), "$0")
or
Me.TxtBox_A_Deposit.Text = Format(Val(Me.TxtBox_A_Percent.Text) / 100 * Val(Me.TxtBox_AB_Qty.Text), "$0")
 

insomniac53

Board Regular
Joined
Sep 3, 2013
Messages
104
Thanks so much for that. Yes, it works. The "Val" method is one I haven't used before. I thought the "Cdbl" or "CInt" would work, but they didn't. The Percent and Qty textboxes also force units so I will use the same syntax. Again, many thanks. I didn't think I was going to get any sleep tonight.
 
Last edited:
Master Excel Bundle

Excel contains over 450 functions, with more added every year. That’s a huge number, so where should you start? Right here with this bundle.

Forum statistics

Threads
1,168,088
Messages
5,857,290
Members
431,869
Latest member
Avinashz

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