VLOOKUP and MIN functions

JimRoy

New Member
Joined
Jul 17, 2015
Messages
11
Example worksheets:

I'm trying to resolve for Worksheet1 B2 - B4

I want to find the earliest transaction date in Worksheet2 for each UniqueID in Worksheet1 Column A and place the date in Worksheet1 Column B.

There are only unique ID numbers in A Worksheet 1

Worksheet2 is a transaction table so there are multiple records with the same ID.

I have tried using the VLOOKUP(MIN but am missing something because it just does not work.

I would prefer a function solution vs VBA, if possible.

AB
1UniqueIDActualStartDate
2A123
3A124
4A125

<tbody>
</tbody>








Worksheet1


AB
1UniqueIDTransDate
2A1231/13/16
3A1232/1/16
4A12412/13/16
5A1239/22/16
6A12410/13/16
7A1237/25/16
8A1258/1/16

<tbody>
</tbody>















Worksheet2

Thanks,
 

Excel Facts

Copy formula down without changing references
If you have =SUM(F2:F49) in F50; type Alt+' in F51 to copy =SUM(F2:F49) to F51, leaving the formula in edit mode. Change SUM to COUNT.
Re: Help with VLOOKUP and MIN functions

The worksheet names are confusing when submitted.

Worksheet1 is the upper table.
 
Upvote 0
Re: Help with VLOOKUP and MIN functions

If you sorted Worksheet2 by TransDate (olsest to newest) you could use VLOOKUP.

However, with your current layout, try this, copied down.


Book1
AB
1UniqueIDActualStartDate
2A12313/01/2016
3A12413/10/2016
4A1251/08/2016
Worksheet1
Cell Formulas
RangeFormula
B2=AGGREGATE(15,6,Worksheet2!B$2:B$8/(Worksheet2!A$2:A$8=A2),1)
 
Upvote 0
Re: Help with VLOOKUP and MIN functions

This is working but with some issues. The actual worksheets I'm using are quite a bit larger that my examples. Worksheet1 has approx 13,000 records and Worksheet2 40,000.

Issues:
1. Not all UniqueIDs in Worksheet1 column A have a match in Worksheet2 column A. It appears these missing matches are causing a #Num ! error in Workseett1 Column A. Any ideas how avoid this? I tried the IFERROR function in front of the AGGREGATE formula but it didn't work.
2. When the AGGREGATE function calculates it takes a long time to complete. > 5 min. Is there anyway to speed this up.

Other info: Both of these Worksheets are pulling data from an ODBC connection via SQL statements. The Worksheet2 TransDate field also uses an IF statement to pull dates from another field located in the same table. Is there a way to control when each refresh and calculations run?

Sorry to be pilling on but, devil is always in the details. Any help would be appreciated.
 
Upvote 0
Re: Help with VLOOKUP and MIN functions

Both of these Worksheets are pulling data from an ODBC connection via SQL statements.
I'm not too familiar with that so can't really offer advice about it.



I tried the IFERROR function in front of the AGGREGATE formula but it didn't work.
Maybe it isn't relevant given the size of your data and the speed issue, but IFERROR works fine for me. For the little sample that I used before, this is what I used:
=IFERROR(AGGREGATE(15,6,Worksheet2!B$2:B$8/(Worksheet2!A$2:A$8=A2),1),"Not found")


Worksheet1 has approx 13,000 records and Worksheet2 40,000.
When the AGGREGATE function calculates it takes a long time to complete. > 5 min. Is there anyway to speed this up.
I don't know how dynamic the results need to be, but you could try this macro in a copy of your workbook.
Code:
Sub ActualStartDate()
  Dim d As Object
  Dim a As Variant
  Dim i As Long

  Set d = CreateObject("Scripting.Dictionary")
  With Sheets("Worksheet2")
    a = .Range("A2", .Range("B" & .Rows.Count).End(xlUp)).Value
  End With
  For i = 1 To UBound(a)
    If d.exists(a(i, 1)) Then
      If a(i, 2) < d(a(i, 1)) Then d(a(i, 1)) = a(i, 2)
    Else
      d(a(i, 1)) = a(i, 2)
    End If
  Next i
  With Sheets("Worksheet1")
    a = .Range("A2", .Range("A" & .Rows.Count).End(xlUp)).Value
    ReDim Preserve a(1 To UBound(a), 1 To 2)
    For i = 1 To UBound(a)
      If d.exists(a(i, 1)) Then
        a(i, 2) = d(a(i, 1))
      Else
        a(i, 2) = "Not found"
      End If
    Next i
    .Range("A2").Resize(UBound(a), 2).Value = a
  End With
End Sub
 
Upvote 0
Re: Help with VLOOKUP and MIN functions

I apologize for not being timely but, this worked great. Thank you.
 
Upvote 0

Forum statistics

Threads
1,214,599
Messages
6,120,449
Members
448,966
Latest member
DannyC96

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