Vlook-Up using a Macro

John_Daly

New Member
Joined
Feb 15, 2023
Messages
23
Office Version
  1. 365
Platform
  1. Windows

Excel Facts

Links? Where??
If Excel says you have links but you can't find them, go to Formulas, Name Manager. Look for old links to dead workbooks & delete.
try this: It uses the dictionary object and variant arrays which makes the code super fast even for large numbers of rows.
VBA Code:
Sub DimIndxMat()
   Dim Ary As Variant
   Dim i As Long
   Dim Dic As Object
 
 
   Set Dic = CreateObject("Scripting.dictionary")
   With Worksheets("Sheet1")
      LastRow = .Cells(Rows.Count, "A").End(xlUp).Row
      Ary = .Range(.Cells(1, 1), .Cells(LastRow, 2))
   End With
   For i = 2 To UBound(Ary)
      Dic(Ary(i, 2)) = Ary(i, 1)               ' Load Dictionary with Value in Column A
   Next i
   With Worksheets("Sheet1")
      LastRow = .Cells(Rows.Count, "C").End(xlUp).Row
      inarr = .Range(.Cells(1, 3), .Cells(LastRow, 3))
      outarr = .Range(.Cells(1, 4), .Cells(LastRow, 4))
  
      For i = 2 To LastRow
         If Dic.Exists(inarr(i, 1)) Then  ' check if element exists
         outarr(i, 1) = Dic(inarr(i, 1)) ' Load output array with dictionary value
         Else          ' if it not set to not found
         outarr(i, 1) = "Not Found"
         End If
        
      Next i
      .Range(.Cells(1, 4), .Cells(LastRow, 4)) = outarr  ' write out the output array
    
   End With
End Sub
 
Upvote 1
Solution
Thanks very much and also thanks for considering the large number of rows
 
Upvote 0

Forum statistics

Threads
1,223,630
Messages
6,173,456
Members
452,514
Latest member
cjkelly15

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