Vlookup with duplicate values.

Addictions

Board Regular
Joined
May 27, 2018
Messages
60
Office Version
  1. 365
Hi,
Can somnoe help or navigate me on how to solve this problem
I would want to originaly have a vlookup to return values from Table 2 in to Table 1, A, B, C columns. The problem is with duplicates vlookup will always return the first found value.
Any ideas to solve this?

Table 1
Michael(90)(80)(60)

Table 2
Michael90
Michael80
Ana70
Michael60




Table 1
A B C D
1 Michael (90) (80) (60)


Table 2
A B
1 Michael 90
2 Michael 80
3 Ana 70
4 Michael 60
 
Don't use whole column references, it's just a drain on resources & could freeze your sheet.
 
Upvote 0

Excel Facts

When did Power Query debut in Excel?
Although it was an add-in in Excel 2010 & Excel 2013, Power Query became a part of Excel in 2016, in Data, Get & Transform Data.
I have below code, but you rightly mentioned not to use whole column range. What would I need to do to change in formula to look at the last row in specific column instead of referecncing whole column. Column A always will have data.

VBA Code:
Dim Fnd As Range

Set Fnd = Sheets("Sheet1).Range("1:1").Find("Name")
   If Fnd Is Nothing Then Exit Sub
   Fnd.Offset(, 1).EntireColumn.Insert
   Fnd.Offset(, 1).Value = "Data1"
   With Range(Fnd.Offset(1, 1), Cells(Rows.Count, Fnd.Column).End(xlUp).Offset(, 1))
      .NumberFormat = "dd/mm/yyyy"
      .Formula = "=IFERROR(INDEX(Sheet2!$B:$B,AGGREGATE(15,6,ROW(Sheet2!$B:$B)-ROW(Sheet2!$B$2)+2/(Sheet2!$A:$A=Sheet1!$A2),COLUMNS('Sheet1!$N2:N2))),"""")"

   End With
 
Upvote 0
I am guessing there is no way to implement variable to check the last row as it is inserting formula in to cell.
 
Upvote 0
Please don't be so impatient. ;)

Add this to your code
VBA Code:
   Dim UsdRws As Long
   UsdRws = Sheets("Sheet2").Range("B" & Rows.Count).End(xlUp).Row
and the formula would then be
VBA Code:
   .Formula = "=IFERROR(INDEX(Sheet2!$B2:$B" & UsdRws & ",AGGREGATE(15,6,(ROW(Sheet2!$B2:$B" & UsdRws & ")-ROW(Sheet2!$B$2)+1)/(Sheet2!$A2:$A" & UsdRws & "=Sheet1!$A2),COLUMNS(Sheet1!$N2:N2))),"""")"
 
Upvote 0
I've never read any books or watched videos on VBA, so cannot recommend anything.
I've learnt most of what I know from posting here.
 
Upvote 0

Forum statistics

Threads
1,217,046
Messages
6,134,263
Members
449,862
Latest member
Muhamad Irfandi

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