blank text boxes

mmix803

New Member
Joined
Sep 21, 2024
Messages
16
Office Version
  1. 2021
Platform
  1. Windows
I am new to vba and I have a simple userform in excel. First textbox is qty1txt * second textbox is rate1txt = amount1txt. On the next line is forth textbox is qty2txt * fifthtextbox is rate2txt = amount2txt. Then I have a command button (Calculate total) in my totaltxt textbox. Some times I do not have information and want to have blank textboxes of qty2txt, rate2txt and amount2txt, but I still need a total. This is what I have so far. Any help would be appreciated. Thank you

Option Explicit

Private Sub CommandButton1_Click()

totaltxt.Value = (qty1txt.Value) * (rate1txt.Value) + (qty2txt.Value) * (rate2txt.Value)

End Sub


Private Sub rate1txt_Change()

'calculate the product

amount1txt.Value = (qty1txt.Value) * (rate1txt.Value)

End Sub


Private Sub rate2txt_Change()

'calculate the product
calculate total.PNG

amount2txt.Value = (qty2txt.Value) * (rate2txt.Value)

End Sub
 

Excel Facts

Does the VLOOKUP table have to be sorted?
No! when you are using an exact match, the VLOOKUP table can be in any order. Best-selling items at the top is actually the best.
You have to change this:
VBA Code:
amount2txt.Value = val(qty2txt.Value) * val(rate2txt.Value)

I added Val there so the blank will be 0. You should add for each textbox Val or forced the field to be number (0 in case of empty).
I hope I understood correctly.

Regards,
GB
 
Upvote 0
Solution
I want to add currency to the rate2txt text box. But with the Val function will not recognize the currency and the amount2txt box is zero.
 
Upvote 0
If you want to enter like [ $12 ] in the rate2txt field than add this :

VBA Code:
Private Sub rate2txt_Change()
if rate2txt.Value = vbNullString then
amount2txt.Value = 0
else
amount2txt.Value = val(qty2txt.Value) * val(replace(rate2txt.Value,"$",""))
end if
End Sub

I hope I understood correctly what you want.

Regards,
GB
 
Upvote 0
If you want to enter like [ $12 ] in the rate2txt field than add this :

VBA Code:
Private Sub rate2txt_Change()
if rate2txt.Value = vbNullString then
amount2txt.Value = 0
else
amount2txt.Value = val(qty2txt.Value) * val(replace(rate2txt.Value,"$",""))
end if
End Sub

I hope I understood correctly what you want.

Regards,
GB
 
Upvote 0
I said something else in my reply, I said if you literally enter $12 in the rate2txt field that will work.

Regards,
GB
 
Upvote 0
Thank you. Works like a charm and no error.
The marked solution has been changed accordingly. In your future questions, please mark the post as the solution that actually answered your question, instead of your feedback message as it will help future readers. No further action is required for this thread.
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,184
Members
453,020
Latest member
Mohamed Magdi Tawfiq Emam

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