Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 84
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 29
Default 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
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
database extract having 3 common cell betwenn sheets deval shah Excel Worksheet Functions 2 November 8th 08 04:48 PM
comboboxes Zaahir Excel Programming 1 October 27th 06 02:43 PM
add value of 4 cells, multiply by 3 subtract 72 multiply by 80% George A. Yorks Excel Discussion (Misc queries) 10 October 25th 06 09:45 PM
If value betwenn 0% and 50% than yes chrismania[_6_] Excel Programming 6 October 24th 03 11:06 PM
Comboboxes David W[_3_] Excel Programming 1 August 29th 03 11:13 PM


All times are GMT +1. The time now is 11:06 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"