Multiplying text box values - correct syntax

insomniac53

Board Regular
Joined
Sep 3, 2013
Messages
102
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.
 

Some videos you may like

Excel Facts

How to total the visible cells?
From the first blank cell below a filtered data set, press Alt+=. Instead of SUM, you will get SUBTOTAL(9,)

mikerickson

MrExcel MVP
Joined
Jan 15, 2007
Messages
23,907
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
102
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:

Watch MrExcel Video

Forum statistics

Threads
1,122,554
Messages
5,596,814
Members
414,104
Latest member
imamalidadashzada

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