Index Match to Fill Columns in VBA

Clarkwr3

New Member
Joined
Feb 11, 2021
Messages
6
Office Version
  1. 365
Platform
  1. Windows
I cannot for the life of me figure out how to call out a named range when using Index match in VBA. From what I can find it sounds like maybe you cant but then also I cant find a workaround.

What Im looking for is to replace "Range("D2")" in the match function with a named range. Not in VBA I would enter the formula and fill down but that just copies the same value when you use autofill.

Heres what I have. DR and OP are named worksheets. The Part.Value returns the same part down the entire range based on the first match (expected). Now how to I tell it to look at cell B3 when filling A3? I had a range named "WO" that has all of the values in column D but cannot put "WO" into the match.

Dim DataTbl As Range
Dim MatchRng As Range
DR.Activate
Set DataTbl = DR.Range("$A:$R")
Set MatchRng = DR.Range("$C:$C")
'
Dim Parts As Range
OP.Activate
Set Parts = OP.Range(Cells(2, 2), Cells(L, 2))
'
Parts.Value = Application.WorksheetFunction.Index(DataTbl, Application.WorksheetFunction.Match(Range("D2"), MatchRng, 0), 1)

I appreciate the help in advance, new to VBA so this has been an all day event
 

Attachments

  • Capture.JPG
    Capture.JPG
    63.6 KB · Views: 17

Excel Facts

Square and cube roots
The =SQRT(25) is a square root. For a cube root, use =125^(1/3). For a fourth root, use =625^(1/4).
For Each Cell In Parts
Cell.Value = Application.WorksheetFunction.Index(DataTbl, Application.WorksheetFunction.Match(Cell.Offset(, 1), MatchRng, 0), 1)
Next
 
Upvote 0
Solution
Dude you are awesome thank you! I was reading up on arrays last night until my head was spinning. Half the battle is knowing what keywords to google so Offset will be a useful addition.
 
Upvote 0

Forum statistics

Threads
1,214,591
Messages
6,120,425
Members
448,961
Latest member
nzskater

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