Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
Combobox Value
Hi!!
I´m having trouble with subtract the value of the current item in my combobox, I´ve created an combobox with to items A and B in excel. Later I need to reach the the choosen value. So how to i get the value that is displayed in the combobox. Im using value now. But this gives me the offset value doesnt change when I change comboitem. Here is my code: Sub testCombo() Dim oWs As Worksheet Dim oOLE As OLEObject Dim combo As ComboBox Set oWs = ActiveSheet Dim cell As Range 'To set with a cell With Range("F8") Set oOLE = ActiveSheet.OLEObjects.Add(ClassType:="Forms.combo box.1", _ Left:=.Left, Top:=.Top, Width:=.Width, Height:=.Height) .ShrinkToFit = False .MergeCells = False .WrapText = True Set combo = oOLE.Object combo.Font.Size = 8 combo.ForeColor = RGB(255, 255, 255) combo.AddItem ("A") combo.ForeColor = RGB(0, 0, 255) combo.AddItem ("B") combo.ListIndex = 0 combo.Placement = xlMoveAndSize combo.PrintObject = True End With Set cell = Cells(13, 5) MsgBox combo.Value End Sub ............................................... Can somebody plz help me, thx |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
Combobox Value
You code worked fine for me. It displayed A in the msgbox.
Later I changed the value manually and then ran: Sub showbox() MsgBox ActiveSheet.OLEObjects(1).Object.Value End Sub and it returned the correct value. -- Regards, Tom Ogilvy "Amoni" wrote in message ... Hi!! I´m having trouble with subtract the value of the current item in my combobox, I´ve created an combobox with to items A and B in excel. Later I need to reach the the choosen value. So how to i get the value that is displayed in the combobox. Im using value now. But this gives me the offset value doesnt change when I change comboitem. Here is my code: Sub testCombo() Dim oWs As Worksheet Dim oOLE As OLEObject Dim combo As ComboBox Set oWs = ActiveSheet Dim cell As Range 'To set with a cell With Range("F8") Set oOLE = ActiveSheet.OLEObjects.Add(ClassType:="Forms.combo box.1", _ Left:=.Left, Top:=.Top, Width:=.Width, Height:=.Height) .ShrinkToFit = False .MergeCells = False .WrapText = True Set combo = oOLE.Object combo.Font.Size = 8 combo.ForeColor = RGB(255, 255, 255) combo.AddItem ("A") combo.ForeColor = RGB(0, 0, 255) combo.AddItem ("B") combo.ListIndex = 0 combo.Placement = xlMoveAndSize combo.PrintObject = True End With Set cell = Cells(13, 5) MsgBox combo.Value End Sub .............................................. Can somebody plz help me, thx |
#3
Posted to microsoft.public.excel.programming
|
|||
|
|||
Combobox Value
Amoni,
What do you mean that you are getting the offset, do you mean you get its index not the A or B? Msgbox .Value is giving A in your code as would be expected. -- HTH RP (remove nothere from the email address if mailing direct) "Amoni" wrote in message ... Hi!! I´m having trouble with subtract the value of the current item in my combobox, I´ve created an combobox with to items A and B in excel. Later I need to reach the the choosen value. So how to i get the value that is displayed in the combobox. Im using value now. But this gives me the offset value doesnt change when I change comboitem. Here is my code: Sub testCombo() Dim oWs As Worksheet Dim oOLE As OLEObject Dim combo As ComboBox Set oWs = ActiveSheet Dim cell As Range 'To set with a cell With Range("F8") Set oOLE = ActiveSheet.OLEObjects.Add(ClassType:="Forms.combo box.1", _ Left:=.Left, Top:=.Top, Width:=.Width, Height:=.Height) .ShrinkToFit = False .MergeCells = False .WrapText = True Set combo = oOLE.Object combo.Font.Size = 8 combo.ForeColor = RGB(255, 255, 255) combo.AddItem ("A") combo.ForeColor = RGB(0, 0, 255) combo.AddItem ("B") combo.ListIndex = 0 combo.Placement = xlMoveAndSize combo.PrintObject = True End With Set cell = Cells(13, 5) MsgBox combo.Value End Sub .............................................. Can somebody plz help me, thx |
#4
Posted to microsoft.public.excel.programming
|
|||
|
|||
Combobox Value
Are you trying to get the selected value to show in the cell (13,5)? You
have done nothing to link the combobox to a cell; you would need to add that and by using a forms combobox you would need to programatically add the code. It would be easier to use the Excel Dropdown; oWs.Dropdowns.Add. -- - K Dales "Amoni" wrote: Hi!! I´m having trouble with subtract the value of the current item in my combobox, I´ve created an combobox with to items A and B in excel. Later I need to reach the the choosen value. So how to i get the value that is displayed in the combobox. Im using value now. But this gives me the offset value doesnt change when I change comboitem. Here is my code: Sub testCombo() Dim oWs As Worksheet Dim oOLE As OLEObject Dim combo As ComboBox Set oWs = ActiveSheet Dim cell As Range 'To set with a cell With Range("F8") Set oOLE = ActiveSheet.OLEObjects.Add(ClassType:="Forms.combo box.1", _ Left:=.Left, Top:=.Top, Width:=.Width, Height:=.Height) .ShrinkToFit = False .MergeCells = False .WrapText = True Set combo = oOLE.Object combo.Font.Size = 8 combo.ForeColor = RGB(255, 255, 255) combo.AddItem ("A") combo.ForeColor = RGB(0, 0, 255) combo.AddItem ("B") combo.ListIndex = 0 combo.Placement = xlMoveAndSize combo.PrintObject = True End With Set cell = Cells(13, 5) MsgBox combo.Value End Sub .............................................. Can somebody plz help me, thx |
#5
Posted to microsoft.public.excel.programming
|
|||
|
|||
Combobox Value
It didn´t work for me. So do u mean that after running my code that creates a
combobox with two alternative A and B. You can change form A to B and reach the current Value in the combobox using: Sub showbox() MsgBox ActiveSheet.OLEObjects(1).Object.Value End Sub and it will return B? |
#6
Posted to microsoft.public.excel.programming
|
|||
|
|||
Combobox Value
With offset I meant the first item added to the combobox and that i A. But I
want to when changing manually in excel from A to B, my msgBox to display B and not still A. Do u understand my problem? //Amoni |
#7
Posted to microsoft.public.excel.programming
|
|||
|
|||
Combobox Value
Hi ! Yes Im trying to get the selected value to display in cell(13,5) just to notify if the action is correct. Didnt understand what u meant with "to add that and by using a forms combobox you would need to programatically add the code. " |
#8
Posted to microsoft.public.excel.programming
|
|||
|
|||
Combobox Value
If B is selected and your combobox is the first in the OleObjects
collection. My suggestion is illustrative. I have no idea how you have your sheet set up, but the suggestion could be altered to specifically address your problem. -- Regards, Tom Ogilvy "Amoni" wrote in message ... It didn´t work for me. So do u mean that after running my code that creates a combobox with two alternative A and B. You can change form A to B and reach the current Value in the combobox using: Sub showbox() MsgBox ActiveSheet.OLEObjects(1).Object.Value End Sub and it will return B? |
#9
Posted to microsoft.public.excel.programming
|
|||
|
|||
Combobox Value
It would have been easier to set up as the built-in Excel .Dropdown object -
the code would have been easier, in my opinion. But what you need to do with your combo is to set the LinkedCell property to be the address of the cell you want. put this line in the code where you are setting the combo's properties: combo.LinkedCell = Cells(13, 5).Address Then I think it will behave the way you want. -- - K Dales "Amoni" wrote: Hi ! Yes Im trying to get the selected value to display in cell(13,5) just to notify if the action is correct. Didnt understand what u meant with "to add that and by using a forms combobox you would need to programatically add the code. " |
#10
Posted to microsoft.public.excel.programming
|
|||
|
|||
Combobox Value
Yes, and I still don't see the problem. If you add this to the combo click
event MsgBox Comobox1.Value You get either A or B when you select from it. -- HTH RP (remove nothere from the email address if mailing direct) "Amoni" wrote in message ... With offset I meant the first item added to the combobox and that i A. But I want to when changing manually in excel from A to B, my msgBox to display B and not still A. Do u understand my problem? //Amoni |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
fill combobox depending on selection from another combobox | Excel Discussion (Misc queries) | |||
How Do I Load A ComboBox RowSource From The Results Of Another ComboBox | Excel Programming | |||
Populating combobox from another combobox | Excel Programming | |||
Combobox | Excel Programming | |||
ComboBox | Excel Programming |