Return last value - matching text in two columns

smide

Board Regular
Joined
Dec 20, 2015
Messages
162
Office Version
  1. 2016
Platform
  1. Windows
Hello.


In columns C and D (C3:D600) I have a product list (about 25 different products) and in columns F and G (F3:G600) their corresponding prices.
When product is in column C his price is in column F, and when product is in column D his price is in column G.


In column I there is a list of ALL products.


I need last value for each product - results should be in column J. (J3...)


example.


CDEFGHIJ
1
2ProductsResults
3appleorange125apple29
4cookieflour247orange8
5toysapple182cookie6
6orangeflour1431flour31
7cookieapple629toys27
8orangetoys827....
9.............

<tbody>
</tbody>

*Note: there is no two identical products in the same row
 
Last edited:

Excel Facts

Format cells as time
Select range and press Ctrl+Shift+2 to format cells as time. (Shift 2 is the @ sign).
Try...

J3, confirmed with CONTROL+SHIFT+ENTER, and copied down:

=LOOKUP(9.99999999999999E+307,IF($C$3:$C$8=I3,$F$3:$F$8,IF($D$3:$D$8=I3,$G$3:$G$8)))

Adjust the ranges accordingly.

Hope this helps!
 
Last edited:
Upvote 0
Here's a macro alternative. Assumes the layout of your data is as in post #1 and generates the results as in that layout.
Code:
Sub LastPrice()
Dim R As Range, Vin As Variant, Vprods As Variant, d As Object, x, i As Long, j As Long, k As Long
Set R = Range("C3:G" & Cells(Rows.Count, "G").End(xlUp).Row)
Vin = R.Value
Application.ScreenUpdating = False
Range("I2:J2").Value = Array("Products", "Results")
Set d = CreateObject("Scripting.dictionary")
For i = LBound(Vin, 1) To UBound(Vin, 1)
    For j = LBound(Vin, 2) To UBound(Vin, 2) - 3
        x = d.Item(Vin(i, j))
    Next j
Next i
With Range("I3").Resize(d.Count, 1)
    .Value = Application.Transpose(d.keys)
    Vprods = .Resize(, 2).Value
    For i = LBound(Vprods, 1) To UBound(Vprods, 1)
        For j = LBound(Vin, 1) To UBound(Vin, 1)
            For k = LBound(Vin, 2) To UBound(Vin, 2)
                If Vin(j, k) = Vprods(i, 1) Then
                    Select Case k
                        Case 1: Vprods(i, 2) = Vin(j, 4)
                        Case 2: Vprods(i, 2) = Vin(j, 5)
                    End Select
                End If
            Next k
        Next j
    Next i
    .Resize(, 2).Value = Vprods
End With
Application.ScreenUpdating = True
End Sub
 
Last edited:
Upvote 0

Forum statistics

Threads
1,215,497
Messages
6,125,157
Members
449,208
Latest member
emmac

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