Dynamic Index Match

kj1

New Member
Joined
Jan 21, 2021
Messages
2
Office Version
  1. 365
Platform
  1. Windows
Okay so I am stuck trying to create this macro that will be able to quickly autofill the columns needed. I have data on multiple workbooks inside the same worksheet and I am trying to combine certain columns from each worksheet into one. The problem that I am running into is how I can make the ranges dynamic since the data will change. The code below works for a static range, but will not be useful without it being dynamic.

I want the "Master" sheet to look like the "After Macro" sheet when it is all complete. Any help would be greatly appreciated!



Dim Last As Double
With ActiveSheet
Last = .Cells(.Rows.Count, "B").End(xlUp).Row
End With
Range("C2").Formula = _
"=INDEX(Data!R2C2:R13C2,MATCH(Master!R2C2,Data!R2C1:R13C1,0))"
Range("C2").AutoFill Destination:=Range("C2:C" & Last)

"Master" Sheet

Test.xlsx
ABCDEFG
1MonthJob #NameStatusTypeDate Total
2OctoberJob 1
3OctoberJob 2
4OctoberJob 3
5OctoberJob 4
6OctoberJob 5
7OctoberJob 6
8OctoberJob 7
9OctoberJob 8
10OctoberJob 9
11OctoberJob 10
12OctoberJob 11
13OctoberJob 12
Master


"Data" Sheet

Test.xlsx
ABCDE
1Job #NameTypeDateZip
2Job 1AAAClean01/12/1945644
3Job 2BBBRepair01/01/2056448
4Job 3CCCFix08/19/2058476
5Job 4DDDWarranty07/05/2096548
6Job 5EEEFix03/30/2076485
7Job 6FFFClean04/11/2048575
8Job 7GGGWarranty06/20/1948756
9Job 8HHHFix04/22/2048785
10Job 9IIIWarranty05/14/2048888
11Job 10JJJRepair05/14/2045721
12Job 11KKKRepair02/02/2064852
13Job 12LLLRepair09/29/2067549
Data


"Status" Sheet

Test.xlsx
ABCD
1Job #StatusCodeTask
2Job 1Complete1Call
3Job 2Complete5Call
4Job 3In Progress77Follow Up
5Job 4Complete44Call
6Job 5In Progress7Call
7Job 6In Progress8Follow Up
8Job 7In Progress6Follow Up
9Job 8In Progress5Follow Up
10Job 9In Progress4Follow Up
11Job 10In Progress58Call
12Job 11In Progress45Call
13Job 12Complete60Follow Up
Status


"Cost" Sheet

Test.xlsx
ABC
1Job #Trips Total
2Job 15$ 1,200.00
3Job 22$ 4,658.00
4Job 315$ (9,857.00)
5Job 42$ 657.00
6Job 565$ 945,756.00
7Job 640$ 20,405.00
8Job 742$ 68,519.00
9Job 844$ 68,741.00
10Job 931$ (1,853.00)
11Job 101$ 197.00
12Job 1159$ 304,985.00
13Job 1210$ 60,721.00
Cost


"After Macro" Sheet

Cell Formulas
RangeFormula
C2:C13C2=INDEX(Data!$B$2:$B$13, MATCH(Master!$B2,Data!$A$2:$A$13,0))
D2:D13D2=INDEX(Status!$B$2:$B$13,MATCH(Master!$B2,Status!$A$2:$A$13,0))
E2:E13E2=INDEX(Data!$C$2:$C$13, MATCH(Master!$B2,Data!$A$2:$A$13,0))
F2:F13F2=INDEX(Data!$D$2:$D$13, MATCH(Master!$B2,Data!$A$2:$A$13,0))
G2:G13G2=INDEX(Cost!$C$2:$C$13,MATCH(Master!$B2,Cost!$A$2:$A$13,0))
 

Excel Facts

Highlight Duplicates
Home, Conditional Formatting, Highlight Cells, Duplicate records, OK to add pink formatting to any duplicates in selected range.
Change "=INDEX(Data!R2C2:R13C2,MATCH(Master!R2C2,Data!R2C1:R13C1,0))"

to

"=INDEX(Data!R2C2:R" & Last & "C2,MATCH(Master!R2C2,Data!R2C1:R" & Last & "C1,0))"
 
Upvote 0
Thank you! I had tried a similar option earlier, but I had the "" in the wrong places which was giving me compile errors. Your method works great!
 
Upvote 0

Forum statistics

Threads
1,215,053
Messages
6,122,888
Members
449,097
Latest member
dbomb1414

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