• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

issues with Vlookup

helloakshay

New Member
I am selecting a value in the combo box and doing a vlookup for 3 column.
The value in the combobox is in Text format.

Example value selected in a combo box is "New York" the value in its column 3 is some 200 /300. so it should show this value.

I know vlookup has some issues while searching with values in text format. hence i have used Trim in vba code still it throws the error.

My range is named "country"

is it ideal to use a vlookup r index and match function here

Code:
'Range("B3:N11") Named as Country

Dim x As Variant
Dim y As Variant
Dim z As String

x = ComboBox1.Value
MsgBox x

y = Application.WorksheetFunction.VLookup(Trim(x), Range("$B$3:$N$11"), 3)
Range("e14").Value = y
End Sub
 

Attachments

  • Book1.xlsm
    23.7 KB · Views: 4
Hello Akshay -

Use the below instead..the underlined and bold part was missing from your codes

Private Sub ComboBox1_Click()
Dim x As Variant
Dim y As Variant
Dim z As String

x = ComboBox1.Value
MsgBox x

y = Application.WorksheetFunction.VLookup(Trim(x), Range("$B$3:$N$11"), 3, 0)
Range("e14").Value = y
End Sub
 
Back
Top