Find row number based on on mulitple criteria

jmjeichavez

New Member
Joined
Sep 8, 2014
Messages
7
Hello,

I am looking for a VBA solution that can find the latest data entry using 2 criteria. For instances, looking at the table below, if i were to enter the employee ID and the product type it would return $79. I am trying to avoid formulas to accomplish this task. Any help would be much much appreciated!

EmployeeID
jc8277
Product
Gloves
Amount
$ 15.00
Updated
EmpID
Product
Amount
9/11/2017 13:08st4345Shoes $ 89.00
9/11/2017 13:11jc8277Gloves $ 15.00
9/11/2017 13:11jc8277Scarf $ 10.00
10/2/2017 12:54bb8899Shoes $ 90.00
10/2/2017 13:16st4345Gloves $ 15.00
10/2/2017 13:16st4345Shoes $ 100.00
10/24/2017 14:34jc8277Shoes $ 79.00
10/24/2017 14:34jc8277Gloves $ 15.00
11/3/2017 10:22bb8899Scarf $ 10.00
11/3/2017 10:22bb8899Gloves $ 15.00

<tbody>
</tbody>
 
This script will work if the dates are in order

I'm not sure how to use "Max" with something like this. When not using filter
Not sure why filter is needed.
Code:
Sub Check_Products_New()
Application.ScreenUpdating = False
Dim i As Long
Dim Lastrow As Long
Dim EmployeeID As String
Dim Product As String
Dim x As Long
x = 1
Lastrow = Cells(Rows.Count, "B").End(xlUp).Row
EmployeeID = Range("B1").Value
Product = Range("B2").Value
    For i = 6 To Lastrow
        If Cells(i, 2).Value = EmployeeID Then
            If Cells(i, 3).Value = Product Then
                x = i
        End If
        End If
         Next
Range("B3").Value = Cells(x, 4).Value
Application.ScreenUpdating = True
End Sub
 
Upvote 0

Excel Facts

Whats the difference between CONCAT and CONCATENATE?
The newer CONCAT function can reference a range of cells. =CONCATENATE(A1,A2,A3,A4,A5) becomes =CONCAT(A1:A5)

Forum statistics

Threads
1,216,095
Messages
6,128,794
Members
449,468
Latest member
AGreen17

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