• 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.

Lookup Last Match of a ComboBox value - VBA

Prima Satria

New Member
Hello,

I want to extract the last driving kilometer of a vehicle ID, let's say 27001 thru a ComboBox1.
The database is store in sheets "Data", and the number of vehicle ID is in column F while the driving kilometer is in column O.
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 click DATA INPUT button in sheet "DATA"

Thanks in advance.
 

Attachments

  • Fuel Consumption.xlsb
    441.1 KB · Views: 3
Hi ,

The problem is in these two lines of code :

TextBox8.Value = Evaluate("=Lookup(2,1/(Data!O4:O23=""" & Me.ComboBox1.Value & """),Data!F4:F23)")

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

The highlighted portion will resolve to the vehicle ID 27001 , 27002 ,.... ; your worksheet tab named Data has this field in column F ; using any other column , such as G or O , will result in an error value being returned , since no match will be found.

Correct the references to refer to column F.

Narayan
 
I changed the code into this, and running well.

Code:
TextBox8.Value = Evaluate("=Lookup(2,1/(Data!F4:F23=""" & Me.ComboBox1.Value & """),Data!O4:O23)")

Thanks so much for your help. I really appreciate it.
Chandoo is the best !!!
 
Back
Top