Index Match with VBA Different Sheet

bhalbach

Board Regular
Joined
Mar 15, 2018
Messages
221
Office Version
  1. 2016
Platform
  1. Windows
I'm really new to VBA and slowly learning but I am struggling with Index and Match.

I have the following code that works great if the Data starts in A1 on both the "Data" sheet and the "VBA Output" sheet.

1. change the LookRange to start at "D9", instead of "A:A"
2. change the SourceRange to "D8:P8"
3. change the Header_Range to "D8:P8
4. the data to lookup starts at D12 (Header) and the last row is D27

I hope I have explained this correctly...I have been working on this forever and just don't understand it. I hope the copied table layout shows correctly.

Please help....




Sub IndexMatch_Function()

Dim x As Integer, y As Integer
Dim SourceRange As Range
Dim LookRange As Range
Dim Header_Range As Range
Dim ws As Worksheet

Set wsD = Sheets("Data")
Set wsVO = Sheets("VBA Output")
Set SourceRange = wsD.Range("A:E")
Set LookRange = wsD.Range("A:A")
Set Header_Range = wsD.Range("1:1")

wsVO.Select

MyLastRow = wsVO.Cells(Rows.Count, 1).End(xlUp).Row
MyLastColumn = wsVO.Cells(1, Columns.Count).End(xlToLeft).Column

For x = 2 To MyLastRow
For y = 2 To MyLastColumn

On Error Resume Next

wsVO.Cells(x, y) = WorksheetFunction.Index(SourceRange, _
WorksheetFunction.Match(wsVO.Cells(x, 1), LookRange, 0), _
WorksheetFunction.Match(wsVO.Cells(1, y), Header_Range, 0))

Next y
Next x

On Error GoTo 0

End Sub



Sheet "Data" (this is a Table "tblLabour") - Header starts at D8 (Dynamic and can grow in rows)
DescriptionBase RateAdjusted Base RateOvertimeSubtotal Base RateVacation RateStat Holiday RateEmployer EI RateEmployer CPP RateEmployer WCB RateHealth BenefitsPension RateBurden Rate
Concrete Finisher
29.00​
29.00​
7.25​
36.25​
2.09​
1.16​
0.80​
1.90​
0.94​
0.00​
0.00​
43.15​
Excavator Operator
30.00​
30.00​
7.50​
37.50​
2.16​
1.20​
0.83​
1.97​
0.98​
0.00​
0.00​
44.64​
Extruder Operator
30.00​
30.00​
7.50​
37.50​
2.16​
1.20​
0.83​
1.97​
0.98​
0.00​
0.00​
44.64​
Foreman
35.00​
35.00​
8.75​
43.75​
2.52​
1.40​
0.97​
2.30​
1.14​
0.00​
0.00​
52.08​
Form Setter
26.00​
26.00​
6.50​
32.50​
1.88​
1.04​
0.72​
1.71​
0.85​
0.00​
0.00​
38.68​
General Labour
23.00​
23.00​
5.75​
28.75​
1.66​
0.92​
0.64​
1.51​
0.75​
0.00​
0.00​
34.22​
General Operator
27.00​
27.00​
6.75​
33.75​
1.95​
1.08​
0.75​
1.77​
0.88​
0.00​
0.00​
40.17​
Grader Operator
31.00​
31.00​
7.75​
38.75​
2.24​
1.24​
0.86​
2.03​
1.01​
0.00​
0.00​
46.12​
Line Setter
26.00​
26.00​
6.50​
32.50​
1.88​
1.04​
0.72​
1.71​
0.85​
0.00​
0.00​
38.68​
Milling Operator
30.00​
30.00​
7.50​
37.50​
2.16​
1.20​
0.83​
1.97​
0.98​
0.00​
0.00​
44.64​
Paver Operator
29.00​
29.00​
7.25​
36.25​
2.09​
1.16​
0.80​
1.90​
0.94​
0.00​
0.00​
43.15​
Rakeman
29.00​
29.00​
7.25​
36.25​
2.09​
1.16​
0.80​
1.90​
0.94​
0.00​
0.00​
43.15​
Screed Man
29.00​
29.00​
7.25​
36.25​
2.09​
1.16​
0.80​
1.90​
0.94​
0.00​
0.00​
43.15​
Skidsteer Operator
27.00​
27.00​
6.75​
33.75​
1.95​
1.08​
0.75​
1.77​
0.88​
0.00​
0.00​
40.17​
Skilled Labour
25.00​
25.00​
6.25​
31.25​
1.80​
1.00​
0.69​
1.64​
0.81​
0.00​
0.00​
37.20​
Supervisor
40.00​
40.00​
10.00​
50.00​
2.89​
1.60​
1.11​
2.63​
1.30​
0.00​
0.00​
59.52​
Truck Driver
24.00​
24.00​
6.00​
30.00​
1.73​
0.96​
0.66​
1.58​
0.78​
0.00​
0.00​
35.71​
0.00​
0.00​
0.00​
0.00​
0.00​
0.00​
0.00​
0.00​
0.00​
0.00​
0.00​

Sheet "VBA Output" (Not a Table) - Header D12 (Only 16 rows including header)
DescriptionEachUtilizationHrsBurden RateExtension
Concrete Finisher1.00
100%​
12​
$ 43.15$ 517.78
Excavator Operator1.00
100%​
12​
$ 44.64$ 535.64
Extruder Operator1.00
100%​
12​
$ 44.64$ 535.64
Milling Operator1.00
100%​
12​
$ 44.64$ 535.64
Paver Operator1.00
100%​
12​
$ 43.15$ 517.78
Rakeman1.00
100%​
12​
$ 43.15$ 517.78
Screed Man1.00
50%​
12​
$ 43.15$ 258.89
Skidsteer Operator1.00
50%​
12​
$ 40.17$ 241.04
 

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.

Forum statistics

Threads
1,214,914
Messages
6,122,211
Members
449,074
Latest member
cancansova

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