Userform combobox question
Maybe you could just pick up both columns when you populate the combobox. (You
don't have to show all the columns that you pick up, either.)
Option Explicit
Private Sub CommandButton1_Click()
Unload Me
End Sub
Private Sub CommandButton2_Click()
With Me.ComboBox1
If .ListIndex < 0 Then
Beep
Else
'pick out the second column
MsgBox .List(.ListIndex, 1)
End If
End With
End Sub
Private Sub UserForm_Initialize()
Dim myRng As Range
With ThisWorkbook.Worksheets("Sheet1")
Set myRng = .Range("a1:b" & .Cells(.Rows.Count, "A").End(xlUp).Row)
End With
With Me.ComboBox1
.ColumnCount = myRng.Columns.Count
.List = myRng.Value
.ColumnWidths = "33;0"
End With
Me.CommandButton1.Caption = "Cancel"
Me.CommandButton2.Caption = "Ok"
End Sub
teepee wrote:
Hello
I have a userform combobox which is linked to the values in column A
I want to find a way in VBA so that when an item is selected from the drop
down menu, it returns the value generated by the formula in the adjacent
cell in column B
So in example below, if I select joe, I want the value 45 put somewhere I
can use it as the input for the next vba variable.
john 25
joe 45
carol 65
Anyone got any ideas?
Many thanks
TP
--
Dave Peterson
|