vlookup problem for comboboxes

maabadi

Well-known Member
Joined
Oct 22, 2012
Messages
2,681
Office Version
  1. 2019
  2. 2016
Platform
  1. Windows
Hi
What is problem with this code

It show error: Run time error: "-2147352571 (80020005)":
Could not set the value property. Type mismatch


Code:
Private Sub ComboBox1_AfterUpdate()
    Dim ws As Worksheet
    Set ws = Worksheets("Sheet2")
    Me.ComboBox2.Value = Evaluate("VLOOKUP(""" & Me.ComboBox1.Value & """,'Sheet2'!B:C,2,FALSE)")
End Sub

I don't define any code for combobox2 and when I click on it , Show error

thanks
 

Excel Facts

Is there a shortcut key for strikethrough?
Ctrl+S is used for Save. Ctrl+5 is used for Strikethrough. Why Ctrl+5? When you use hashmarks to count |||| is 4, strike through to mean 5.
It looks like too many quotes in your Evaluate statement. You're not looking for the literal "Me.ComboBox1", you're looking for what that variable represents, so you don't want to be quoting it, it should stay outside the quotes. Same for the Sheet2, no single quotes.

Try this:
Code:
Me.ComboBox2.Value = Evaluate("VLOOKUP(" & Me.ComboBox1 & ",Sheet2!B:C,2,FALSE)")
 
Last edited:
Upvote 0
It looks like too many quotes in your Evaluate statement. You're not looking for the literal "Me.ComboBox1", you're looking for what that variable represents, so you don't want to be quoting it, it should stay outside the quotes. Same for the Sheet2, no single quotes.

Try this:
Code:
Me.ComboBox2.Value = Evaluate("VLOOKUP(" & Me.ComboBox1 & ",Sheet2!B:C,2,FALSE)")


thanks.
it works .
 
Upvote 0

Forum statistics

Threads
1,214,585
Messages
6,120,394
Members
448,957
Latest member
Hat4Life

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top