hi there,
i have a combobox in a worksheet, and the associated list has 3 columns
I need the value of the third column (col index = 2) in a code I have in one of the modules.
following this thread (http://www.pcreview.co.uk/forums/thread-989754.php) I have tried the myworksheet.oleobjects("mycombobox").object.list(.... ) but it does not seem to work
any hints on how to do that? (which should be quite easy I guess...)
thanks!
Bernat
Last edited by bagullo; 10-28-2010 at 11:07 AM.
Hi,
If I understand you correctly you are wanting to see the 3rd item in the combobox when the form is opened.
Make sure that you have the ColumnCount property set to 3, then in the ColumnWidth property enter
0,0,20
if the last 20 is not wide enough just change it. You may also need to use semi colons instead of commas depending on your local settings.
HTH
Richard Buttrey
If this was useful then please rate it appropriately.
Click the small star iconat the bottom left of my post.
well actually no. Apologies for sloppy explanation.
I'm happy the way the combobox displays, but I want to access by code to the values present on the third column which are not visible to the user since the column has a width of 0 pixels.
any suitable way to access the .list method of a combobox in a worksheet (the code is on a standard module)
thnx!
Hi,
OK, how about
MsgBox UserForm1.ComboBox1.Column(2)
where the (2) is the third column since the index is zero based.
HTH
Richard Buttrey
If this was useful then please rate it appropriately.
Click the small star iconat the bottom left of my post.
Hello ,
Since you did not say which toolbar control you are using, I am providing examples for both types. These examples assume that the code is in a standard VBA module, like Module1. These are only basic examples. There is no object validation or error handling in these macros..
Apparently you have used the ListFillRange property to fill these controls. The ListFillRange property property is available to the Control Toolbox ComboBox control only when it is on a worksheet. The properties for Control Toolbox controls may change depending on where they are placed: VBA UserForm or Worksheet.
Control Toolbox ComboBox Code
This will return the Column 3 value to the variable "X".
Sub GetComboBoxColumn3() 'For Control Toolbox ComboBox Control Dim CB As OLEObject Dim Wks As Worksheet Dim X As Variant Set Wks = Worksheets("Sheet1") Set CB = Wks.OLEObjects("ComboBox1") X = CB.Object.List(CB.ListIndex, 2) End Sub
Forms Toolbar DropDown Code
This will return the Column 3 value to the variable "X".
Sub GetDropDownColumn3() 'For the Forms Drop Down Control 'Assign this macro to the Drop Down Dim DD As Excel.DropDown Dim Rng As Range Dim Wks As Worksheet Dim X As Variant Set Wks = Worksheets("Sheet1") Set DD = Wks.DropDowns(Application.Caller) Set Rng = Evaluate(DD.ListFillRange) X = Rng.Cells(DD.ListIndex, 3) End Sub
If you have any questions, please ask.
Sincerely,
Leith Ross
Remember To Do the Following....
1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.2. Thank those who have helped you by clicking the Starbelow the post.
3. Please mark your post [SOLVED] if it has been answered satisfactorily.
Old Scottish Proverb...
Luathaid gu deanamh maille! (Rushing causes delays!)
thanks a lot!
i was attempting to do the same using a with, but that did not work well... using a oleobject variable makes it work and readable at the same time
btw, in case somebody attempts the first solution... there was a .object missing in the code
X = CB.Object.List(CB.ListIndex, 2) --> CB.object.list(cb.object.listindex,2)
I am using control buttons! sorry for forgetting to say that
regards !
btw 2 -- could not figure out how to mark this thread as [SOLVED], but it certainly is
How to mark a thread Solved
Go to the first post
Click edit
Click Go Advanced
Just below the word Title you will see a dropdown with the word No prefix.
Change to Solved
Click Save
piece of cake!
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks