Data entered into userform is not calculating Type mismatch?

new11

New Member
Joined
Sep 15, 2020
Messages
24
Office Version
  1. 365
Platform
  1. Windows
Hello wonderful excel people,
I am having an issue that has me stumped that I was hoping to get some help on, please.

I have a userfrom with a few text boxes for text and services/products to be written and then another 12 textboxes (tb_sprice1 - tb_sprice12), where I'm able to type prices. There is also a textbox filled with the current GST rate (10) as well as a checkbox that is used if the typed price (in tb_sprice1 -tb_sprice12), either exclude GST or already includes GST. For example, if I type 11 as a price and I leave the checkbox unticked, then the subtotal is $10, the GST is $1 with the grand total $11. If however, I tick the checkbox and type 11 for the price then, the subtotal becomes $11, the GST becomes $1.10 bringing the grand total to $11.10. This is all calculated and then copied to a sheet when a userform command button is pressed.

The issue I'm having is trying to calculate the; GST amount and the Grand Total for when the checkbox is ticked (meaning that GST needs to be added to the typed price) and I really don't know where I'm going wrong and it's driving me insane. I created a userform to see the calculations in real-time with each textbox change event and I seem to be getting an error "Type Mismatch run time 13"

When the data is saved into the sheet the; subtotal excluding GST, the GST amount and then the grand total including GST, are all calculated. I'll place the code where I'm getting the error at the end of this post, but let me know If I should be looking anywhere else or if I should post the entire code.

I've been scratching my head all day on this driving myself mad. Maybe I've been looking at the same thing for too long or perhaps it's something so obvious or straightforward that I'm missing but I'd really really appreciate another set of eyes or any ideas where I might be going wrong before I go crazy. Also my apologies in advance for my semi-messy code and methods, I'm semi-new with not too much experience but am always learning. Also thank you for any ideas or assistance in advance! 😊😊

VBA Code:
''''''''''''''''''add or exclude gst based on userform checkbox'''''''''

''''sub total'''''''
If check_excgst.Value = False Then   ' userform typed price already has GST, so take gst off typed price to find price without gst 
invoice.Range("I32").Value = ((Val(tb_sprice1.Value) * (100 / (100 + Val(tb_gstrate.Value)))) + (Val(tb_sprice2.Value) * (100 / (100 + Val(tb_gstrate.Value)))) + (Val(tb_sprice3.Value) * (100 / (100 + Val(tb_gstrate.Value)))) + _
(Val(tb_sprice4.Value) * (100 / (100 + Val(tb_gstrate.Value)))) + (Val(tb_sprice5.Value) * (100 / (100 + Val(tb_gstrate.Value)))) + (Val(tb_sprice6.Value) * (100 / (100 + Val(tb_gstrate.Value)))) + _
(Val(tb_sprice7.Value) * (100 / (100 + Val(tb_gstrate.Value)))) + (Val(tb_sprice8.Value) * (100 / (100 + Val(tb_gstrate.Value)))) + (Val(tb_sprice9.Value) * (100 / (100 + Val(tb_gstrate.Value)))) + _
(Val(tb_sprice10.Value) * (100 / (100 + Val(tb_gstrate.Value)))) + (Val(tb_sprice11.Value) * (100 / (100 + Val(tb_gstrate.Value)))) + (Val(tb_sprice12.Value) * (100 / (100 + Val(tb_gstrate.Value)))))
Else
If check_excgst.Value = True Then    ''userform typed price does not include gst so sub total is itself
invoice.Range("I32").Value = (Val(tb_sprice1.Value) + Val(tb_sprice2.Value) + Val(tb_sprice3.Value) + Val(tb_sprice4.Value) + Val(tb_sprice5.Value) + Val(tb_sprice6.Value) + Val(tb_sprice7.Value) + _
Val(tb_sprice8.Value) + Val(tb_sprice9.Value) + Val(tb_sprice10.Value) + Val(tb_sprice11.Value) + Val(tb_sprice12.Value))
End If
End If

'''''''''''''''''gst amount'''''''''''''''''''''
If check_excgst.Value = False Then  '''when checkbox is not ticked, then find gst by reverse
invoice.Range("I33") = (Val(tb_sprice1.Value) - ((Val(tb_sprice1.Value) * (100 / (100 + Val(tb_gstrate.Value)))))) + (Val(tb_sprice2.Value) - ((Val(tb_sprice2.Value) * (100 / (100 + Val(tb_gstrate.Value)))))) + (Val(tb_sprice3.Value) - ((Val(tb_sprice3.Value) * (100 / (100 + Val(tb_gstrate.Value)))))) _
+ (Val(tb_sprice4.Value) - ((Val(tb_sprice4.Value) * (100 / (100 + Val(tb_gstrate.Value)))))) + (Val(tb_sprice5.Value) - ((Val(tb_sprice5.Value) * (100 / (100 + Val(tb_gstrate.Value)))))) + (Val(tb_sprice6.Value) - ((Val(tb_sprice6.Value) * (100 / (100 + Val(tb_gstrate.Value)))))) _
+ (Val(tb_sprice7.Value) - ((Val(tb_sprice7.Value) * (100 / (100 + Val(tb_gstrate.Value)))))) + (Val(tb_sprice8.Value) - ((Val(tb_sprice8.Value) * (100 / (100 + Val(tb_gstrate.Value)))))) + (Val(tb_sprice9.Value) - ((Val(tb_sprice9.Value) * (100 / (100 + Val(tb_gstrate.Value)))))) _
+ (Val(tb_sprice10.Value) - ((Val(tb_sprice10.Value) * (100 / (100 + Val(tb_gstrate.Value)))))) + (Val(tb_sprice11.Value) - ((Val(tb_sprice11.Value) * (100 / (100 + Val(tb_gstrate.Value)))))) + (Val(tb_sprice12.Value) - ((Val(tb_sprice12.Value) * (100 / (100 + Val(tb_gstrate.Value))))))
Else
If check_excgst.Value = True Then     '''' when userform checkbox is ticked, then add gst onto typed price
invoice.Range("I33").Value = (Val((tb_sprice1.Value) * Val(tb_gstrate.Value)) / 100) + (Val((tb_sprice2.Value) * Val(tb_gstrate.Value)) / 100) + (Val((tb_sprice3.Value) * Val(tb_gstrate.Value)) / 100) _
+ (Val((tb_sprice4.Value) * Val(tb_gstrate.Value)) / 100) + (Val((tb_sprice5.Value) * Val(tb_gstrate.Value)) / 100) + (Val((tb_sprice6.Value) * Val(tb_gstrate.Value)) / 100) _
+ (Val((tb_sprice7.Value) * Val(tb_gstrate.Value)) / 100) + (Val((tb_sprice8.Value) * Val(tb_gstrate.Value)) / 100) + (Val((tb_sprice9.Value) * Val(tb_gstrate.Value)) / 100) _
+ (Val((tb_sprice10.Value) * Val(tb_gstrate.Value)) / 100) + (Val((tb_sprice11.Value) * Val(tb_gstrate.Value)) / 100) + (Val((tb_sprice12.Value) * Val(tb_gstrate.Value)) / 100)
End If
End If


''''''''''''''''''''''''''''''GRAND TOTAL WITH GST''''''''''''''''''''''''''''''''''''''''''''
If check_excgst.Value = False Then       '''''THIS COPIES AS FALSE ON WORKSHEET but used to calculate properally a cupple of minites ago
 invoice.Range("I34") = invoice.Range("I32").Value = (Val(tb_sprice1.Value) + Val(tb_sprice2.Value) + Val(tb_sprice3.Value) + Val(tb_sprice4.Value) + Val(tb_sprice5.Value) + Val(tb_sprice6.Value) + Val(tb_sprice7.Value) + _
Val(tb_sprice8.Value) + Val(tb_sprice9.Value) + Val(tb_sprice10.Value) + Val(tb_sprice11.Value) + Val(tb_sprice12.Value))
Else
If check_excgst.Value = True Then  
invoice.Range("I34").Value = (((Val((tb_sprice1.Value) * Val(tb_gstrate.Value)) / 100) + Val(tb_sprice1.Value)) + ((Val((tb_sprice2.Value) * Val(tb_gstrate.Value)) / 100) + Val(tb_sprice2.Value)) + ((Val((tb_sprice3.Value) * Val(tb_gstrate.Value)) / 100) + Val(tb_sprice3.Value)) _
+ ((Val((tb_sprice4.Value) * Val(tb_gstrate.Value)) / 100) + Val(tb_sprice4.Value)) + ((Val((tb_sprice5.Value) * Val(tb_gstrate.Value)) / 100) + Val(tb_sprice5.Value)) + ((Val((tb_sprice6.Value) * Val(tb_gstrate.Value)) / 100) + Val(tb_sprice6.Value)) _
+ ((Val((tb_sprice7.Value) * Val(tb_gstrate.Value)) / 100) + Val(tb_sprice7.Value)) + ((Val((tb_sprice8.Value) * Val(tb_gstrate.Value)) / 100) + Val(tb_sprice8.Value)) + ((Val((tb_sprice9.Value) * Val(tb_gstrate.Value)) / 100) + Val(tb_sprice9.Value)) _
+ ((Val((tb_sprice10.Value) * Val(tb_gstrate.Value)) / 100) + Val(tb_sprice10.Value)) + ((Val((tb_sprice11.Value) * Val(tb_gstrate.Value)) / 100) + Val(tb_sprice11.Value)) + ((Val((tb_sprice12.Value) * Val(tb_gstrate.Value)) / 100) + Val(tb_sprice12.Value)))
End If
End If
 
Last edited:

Excel Facts

Which lookup functions find a value equal or greater than the lookup value?
MATCH uses -1 to find larger value (lookup table must be sorted ZA). XLOOKUP uses 1 to find values greater and does not need to be sorted.

Forum statistics

Threads
1,223,889
Messages
6,175,226
Members
452,620
Latest member
dsubash

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