Adjust code to cater for multiple combo boxes

sueanne

Board Regular
Joined
Apr 2, 2014
Messages
81
Hi,

I am having great difficulty trying to work out how to calculate GST on a userform. I apologise for the duplicate post, however the other post probably didn't explain it very well.

I have managed to get the code below to work for cboTax1 however I cannot work out how to adjust this code to cater for multiple combo boxes.
By that I mean, I have cboTax1-10 and I need to perform this calculation for all 10 boxes and put the total of the results to Taxamt Textbox.

Code:
Private Sub cboTax1_change()
If cboTax1.Value = "GST Free" Then
 Taxamt1 = "$0.00"
Else
Taxamt1 = (Total1.Value * (10 / 100))
 End If
Taxamt.Value = Format(Taxamt1, "$#,##0.00")
 End Sub

If anyone can please help that would be greatly appreciated, I have been searching the net for days now, but just cant find anything that works for what I want. Maybe I cant do it how I want? 

Thanks so much!
Sue-Anne
 

Excel Facts

Wildcard in VLOOKUP
Use =VLOOKUP("Apple*" to find apple, Apple, or applesauce
Hi
the dimention longs should have been a doubles
Code:
Function ComboBox_Calx(ComboBoxIndex) As Double
    If IsNull(ComboBoxIndex) Or Not IsNumeric(ComboBoxIndex) Then
        ComboBox_Calx = 0
    Else
        
        ComboBox_Calx = ComboBoxIndex * (0.1)
    End If
End Function

Sub Textbox_Calx()
    Dim cCont As Control, TextValue As Double
    For Each cCont In Me.Controls
        If TypeName(cCont) = "ComboBox" Then
            TextValue = TextValue + ComboBox_Calx(cCont.Value)
        End If
    Next cCont
    Me.TextBox1.Value = Format(TextValue, "$#,##0.00")
End Sub
 
Last edited:
Upvote 0
pike you have to see the Userform actually there are 10 rows which needs to be checked and if the tax combobox in one row changes it has to calculate the ten rows from scratch to get the total amount I have to think about a good solution (its a shopping card)
 
Upvote 0
would it be any easier if I add another box to each row, which calculates the gst for each row. Then the taxamt text box at bottom just sums up those ten tax amounts?
 
Upvote 0
sueanne
if you can understand and adapt the Class event solution to trigger the function it is the way to go.thgis is a perfect example of how and where to use a class. The module code is very similar and just uses the combbox change event to trigger the function. Both recalculate the ten comboboxes each time you make a change; which takes about a micro second. if you wanted to show each gst in a seperate text box it would still recalculate ten times to get the same result .probably be a good idea to show the lump sum gst amount and then excluding gst and GST, but it depends on what you need the figures for.
 
Upvote 0
Hi pike,

Sorry I thought I had replied to your latest post, but it must timed out before I sent it.

I have worked out that, it is calculating 10% on one of the comboboxes in my userform, and it needs to calculate 10% on a textbox called Total1-10.

Also, it isn't picking up if GST Free to calculate $0 tax.

I am still working on playing around with the code to try and work out how to get this working properly. Hopefully can get this working :/
 
Upvote 0
sueanne can you tell me what to calculate if the checkbox is:
GSTfree - I guess total price = total price (no tax)
GST - total price and whats the tax ?
 
Upvote 0
sueanne I've sent you the workbook per mail as you might have recognized most of the Userform Comboboxes change events I have removed from the Userform and put it in a module
I'm not quite sure how to get the disc % but the calculation of the disc % and the total we can put to the combo_IC_change Sub all together which would make your coding much simpler.
 
Upvote 0

Forum statistics

Threads
1,215,416
Messages
6,124,772
Members
449,187
Latest member
hermansoa

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