Lookup Last Match of a ComboBox value - VBA

CakzPrimz

Board Regular
Joined
Oct 6, 2017
Messages
57
Hello,

I want to extract the last driving kilometer of a vehicle ID, let's say 27001 thru a ComboBox.
The database is store in sheets "Data", and the number of vehicle ID is in column C while the driving kilometer is in column G.
So, when I change the vehicle ID in ComboBox1 then it will lookup the last driving kilometer in TextBox8.

Below the code I have which not work.

Code:
Private Sub ComboBox1_Change()
'TextBox8.Value = Application.Lookup(2, 1 / Worksheets("Data").Range("R4C7:R23C7") = Me.ComboBox1.Value, Worksheets("Data").Range("R4C5:R23C5"))
End Sub

Please help me to fix it.
Thanks
 

Excel Facts

How to total the visible cells?
From the first blank cell below a filtered data set, press Alt+=. Instead of SUM, you will get SUBTOTAL(9,)
Hi. See if this works:

Code:
TextBox8.Value = Evaluate("=Lookup(2,1/(Data!G4:G23=""" & Me.ComboBox1.Value & """),Data!E4:E23)")
 
Upvote 0
Hi. See if this works:

Code:
TextBox8.Value = Evaluate("=Lookup(2,1/(Data!G4:G23=""" & Me.ComboBox1.Value & """),Data!E4:E23)")


Hi Steve,

Thanks for the response, when I ran the code it gave me
"run time error. Could not set the Value property. Type mismatch".

When I checked the type of vehicle ID is number, not text. Is this triggering the error above?
What should I do, do I have to change the type from number into text type?

Best regards
 
Upvote 0
Try:


TextBox8.Value = Evaluate("=Lookup(2,1/(Data!G4:G23=" & Me.ComboBox1.Value & "),Data!E4:E23)")
 
Upvote 0
Hi Steve,

Thanks again for your assistance, I still got the same error with this code below:

Code:
[COLOR=#574123]TextBox8.Value = Evaluate("=Lookup(2,1/(Data!G4:G23=" & Me.ComboBox1.Value & "),Data!E4:E23)")[/COLOR]

Thanks
 
Upvote 0
Im going to say that the combobox1.Value is not found in the range Data!G4:G23. That would produce an error. You could stop the error manifesting in the runtime error like this for example:

Code:
TextBox8.Value = ""
x = Evaluate("=Lookup(2,1/(Data!G4:G23=" & Me.ComboBox1.Value & "),Data!E4:E23)")
If Not IsError(x) Then
    TextBox8.Value = x
End If
 
Last edited:
Upvote 0
Dear Steve,

Thanks so much for your help and assistance, based on your suggestion I made this changes and now it works !!! Problem solved.

Code:
TextBox8.Value = Evaluate("=Lookup(2,1/(Data!E4:E23=""" & Me.ComboBox1.Value & """),Data!G4:G23)")

Again, thank you Steve and MrExcel
 
Upvote 0

Forum statistics

Threads
1,215,219
Messages
6,123,678
Members
449,116
Latest member
HypnoFant

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