PDA

View Full Version : Combobox selection



riya787
03-05-2012, 01:39 PM
Hi, I have a excel sheet which has two columns one is consisting of table names and the other is the variable names. In the Userform, the user selects the table name from the drop down box given. After selection, i want the variables to be displayed in the listbox pertaining to that table. the variables are prefixed by the table name for eg: tbl_1.name.I don't know how to do it and finding it difficult since i am new to the vba environment.

Bob Phillips
03-05-2012, 02:47 PM
You would have to loop and load them



With Worksheets("Sheet1")

lastrow=.Cells(.Rows.Count, "B").End(xlUp).Row

ListBox1.Clear
For i = 2 To lastrow

If Left$(.Cells(i, "B").Value, Len(ComboBox1.Value)) = ComboBox1.Value Then

ListBox1.AddItem .Cells(i, "B").Value
End If
Next i
End With

riya787
03-05-2012, 10:51 PM
Hey thanks it worked. Thank you so much...
:bow:

riya787
03-06-2012, 11:55 AM
Hi, my excel sheet consist of table names and variables and i am using a simple vlookup function to get the corresponding variable names for the particular table but the function is not working.In this the user selects the table names from the drop down box and then the listbox should enter the corresponding variable names.
my vlookup function for the Combobox is
ListBox1.Value=Application.WorksheetFunction.VLookup(Me.ComboBox1.Value, Range("A:B"), 2, False)

riya787
03-07-2012, 01:33 AM
The following code is not working and it is not taking up the Vlookup value for the variable


Public Sub cboTableName_Click()
Dim i As Integer
Dim lastrow As String
Dim Value As String
With Worksheets("Sheet1")

lastrow = .Cells(.Rows.Count, "B").End(xlUp).Row

AddList.Clear
For i = 2 To lastrow


AddList.AddItem .Cells(i, "B").Value = Application.WorksheetFunction.VLookup(Me.cboTableName.Value, Range("A:B"), 2, False)
Next i
End With
End Sub

vds1
03-07-2012, 01:51 AM
Have you given a thought on evaluate function in VBA?

Bob Phillips
03-07-2012, 03:31 AM
Why don't you post the workbook you are using, complete with working/non-working code, rather than a workbook with just a simple list that helps not a jot.

riya787
03-09-2012, 09:52 AM
Hi, the following attachment is my workbook on which i am working on. The code which i have written is not giving the output which i want and it is printing 0. I know for a list of variables to be entered in the listbox i should use some other function other than VLookup. But i don't know which one i should use so that it gives me the variables according to the table name which i have mentioned in the drop down box. I hope you could help me with that.