Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
Sum , multiply betwenn 2 comboboxes
I have 2 combboxes in a user form,
txtprice = 5 txtqty = 2 And i want in the third combobox to display the result of the multiplication of ( txtprice * txtqy ) And in another user form i want to the same but instead of multiplicacion I want to divide the 2 combboxes. Actually I did it, but i get an error wich says "Type Mismatch"? Can anybody help me. Thanks |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
Sum , multiply betwenn 2 comboboxes
On Apr 17, 3:52 pm, Carlos wrote:
I have 2 combboxes in a user form, txtprice = 5 txtqty = 2 And i want in the third combobox to display the result of the multiplication of ( txtprice * txtqy ) And in another user form i want to the same but instead of multiplicacion I want to divide the 2 combboxes. Actually I did it, but i get an error wich says "Type Mismatch"? Can anybody help me. Thanks You're probably getting a type mismatch because your comboboxes are not being recognized as integers. I've found that declaring an integer variable for each combobox works well, that way you can also set the value of your last one. Although are there fixed prices? If not then why not use a regular textbox? For example: Dim txtpriceVar, txtqtyVar as Integer On Error GoTo Int_fix txtpriceVar = Me.txtprice.Value 'assuming txtprice is the name of your combobox txtqtyVar = Me.txtqty.Value Int_fix: MsgBox("Make sure you have inputed an integer!") Exit Sub Me.third_combo_box.Value = txtpriceVar * txtqtyVar Me.fourth_combo_box.Value = txtpriceVar / txtqtyVar With this you are guaranteed not to have the type mismatch. You could put an error handler before your integer declarations to insure that the person inputing information has not entered any spaces or non- integers. I just ran into this error today and, though I may be wrong, it appears as if Excel strips off the space when you set it as an integer. I was comparing two different text boxes that were "supposed" to have integers in them and even when I printed out their values agreed with each other, but I still got the type mismatch, so I implemented the integer variables. Hope this helps. Andrew |
#3
Posted to microsoft.public.excel.programming
|
|||
|
|||
Sum , multiply betwenn 2 comboboxes
There are a couple other tricks to try here as well. One is to use the
Val() function to extract the numeric value of the combobox rather than its text representation. This can get around blanks, etc. in the user input which can cause Excel to treat things as a string (and thus "Type mismatch"). A shortcut -- and at times a dangerous one -- is simply to multiply the value of the combo box by 1 before using it. This also forces a type conversion. Finally is you have defined "ControlSource" and "RowSource" ranges for the combobox, look at how the underlying ranges are formatted, and in particular look for 'Text' formatting and change it to some variaton of 'number'. This formatting shouldn't make a difference of course, but experience suggests otherwise. / Tyla / On Apr 17, 2:52 pm, Carlos wrote: I have 2 combboxes in a user form, txtprice = 5 txtqty = 2 And i want in the third combobox to display the result of the multiplication of ( txtprice * txtqy ) And in another user form i want to the same but instead of multiplicacion I want to divide the 2 combboxes. Actually I did it, but i get an error wich says "Type Mismatch"? Can anybody help me. Thanks |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
database extract having 3 common cell betwenn sheets | Excel Worksheet Functions | |||
comboboxes | Excel Programming | |||
add value of 4 cells, multiply by 3 subtract 72 multiply by 80% | Excel Discussion (Misc queries) | |||
If value betwenn 0% and 50% than yes | Excel Programming | |||
Comboboxes | Excel Programming |