VBA Index / Match?

BenGee

Board Regular
Joined
Mar 5, 2016
Messages
196
Hi,

I have 2 worksheets, one called "Rota" & one called "Day Plan".

Within the Rota worksheet, I have dates between B2:AE2, a list of names between A5:A7,A9:A17,A19:A24,A26:A35 and then various values between B5:AE35

Within the Day Plan worksheet, I have the same names but between B4:B6,B10:B18,B22:B27,B31:B40 and blank cells AM4:AM6,AM10:AM18,AM22:AM27,AM31:AM40

Within the Day Plan worksheet, I want to lookup the names between B4:B6,B10:B18,B22:B27,B31:B40 within the Rota Sheet A5:A7,A9:A17,A19:A24,A26:A35 and todays date within the rota sheet between B5:AE35 and find the cross-point (e.g. The cross-point between H2 and B10 = H10).

Then once this has been found, put the value that's within the cross-point into the Day Plan range AM4:AM6,AM10:AM18,AM22:AM27,AM31:AM40 (on the same row as the look up name between B4:B6,B10:B18,B22:B27,B31:B40 within the same sheet).

Hope this makes sense and thanks in advance.
 

Excel Facts

Workdays for a market open Mon, Wed, Friday?
Yes! Use "0101011" for the weekend argument in NETWORKDAYS.INTL or WORKDAY.INTL. The 7 digits start on Monday. 1 means it is a weekend.
I've worked it out now :)

Code:
Sub Button69_Click()
    Range("AM4").FormulaArray = "=INDEX(Shifts!$B$5:$AE$35,MATCH('Day Plan'!B4,Shifts!$A$5:$A$35,0),MATCH(TODAY(),Shifts!$B$2:$AE$2,0))"
    Range("AM5").FormulaArray = "=INDEX(Shifts!$B$5:$AE$35,MATCH('Day Plan'!B5,Shifts!$A$5:$A$35,0),MATCH(TODAY(),Shifts!$B$2:$AE$2,0))"
    Range("AM6").FormulaArray = "=INDEX(Shifts!$B$5:$AE$35,MATCH('Day Plan'!B6,Shifts!$A$5:$A$35,0),MATCH(TODAY(),Shifts!$B$2:$AE$2,0))"
    Range("AM10").FormulaArray = "=INDEX(Shifts!$B$5:$AE$35,MATCH('Day Plan'!B10,Shifts!$A$5:$A$35,0),MATCH(TODAY(),Shifts!$B$2:$AE$2,0))"
    Range("AM11").FormulaArray = "=INDEX(Shifts!$B$5:$AE$35,MATCH('Day Plan'!B11,Shifts!$A$5:$A$35,0),MATCH(TODAY(),Shifts!$B$2:$AE$2,0))"
    Range("AM12").FormulaArray = "=INDEX(Shifts!$B$5:$AE$35,MATCH('Day Plan'!B12,Shifts!$A$5:$A$35,0),MATCH(TODAY(),Shifts!$B$2:$AE$2,0))"
    Range("AM13").FormulaArray = "=INDEX(Shifts!$B$5:$AE$35,MATCH('Day Plan'!B13,Shifts!$A$5:$A$35,0),MATCH(TODAY(),Shifts!$B$2:$AE$2,0))"
    Range("AM14").FormulaArray = "=INDEX(Shifts!$B$5:$AE$35,MATCH('Day Plan'!B14,Shifts!$A$5:$A$35,0),MATCH(TODAY(),Shifts!$B$2:$AE$2,0))"
    Range("AM15").FormulaArray = "=INDEX(Shifts!$B$5:$AE$35,MATCH('Day Plan'!B15,Shifts!$A$5:$A$35,0),MATCH(TODAY(),Shifts!$B$2:$AE$2,0))"
    Range("AM16").FormulaArray = "=INDEX(Shifts!$B$5:$AE$35,MATCH('Day Plan'!B16,Shifts!$A$5:$A$35,0),MATCH(TODAY(),Shifts!$B$2:$AE$2,0))"
    Range("AM17").FormulaArray = "=INDEX(Shifts!$B$5:$AE$35,MATCH('Day Plan'!B17,Shifts!$A$5:$A$35,0),MATCH(TODAY(),Shifts!$B$2:$AE$2,0))"
    Range("AM18").FormulaArray = "=INDEX(Shifts!$B$5:$AE$35,MATCH('Day Plan'!B18,Shifts!$A$5:$A$35,0),MATCH(TODAY(),Shifts!$B$2:$AE$2,0))"
    Range("AM22").FormulaArray = "=INDEX(Shifts!$B$5:$AE$35,MATCH('Day Plan'!B22,Shifts!$A$5:$A$35,0),MATCH(TODAY(),Shifts!$B$2:$AE$2,0))"
    Range("AM23").FormulaArray = "=INDEX(Shifts!$B$5:$AE$35,MATCH('Day Plan'!B23,Shifts!$A$5:$A$35,0),MATCH(TODAY(),Shifts!$B$2:$AE$2,0))"
    Range("AM24").FormulaArray = "=INDEX(Shifts!$B$5:$AE$35,MATCH('Day Plan'!B24,Shifts!$A$5:$A$35,0),MATCH(TODAY(),Shifts!$B$2:$AE$2,0))"
    Range("AM25").FormulaArray = "=INDEX(Shifts!$B$5:$AE$35,MATCH('Day Plan'!B25,Shifts!$A$5:$A$35,0),MATCH(TODAY(),Shifts!$B$2:$AE$2,0))"
    Range("AM26").FormulaArray = "=INDEX(Shifts!$B$5:$AE$35,MATCH('Day Plan'!B26,Shifts!$A$5:$A$35,0),MATCH(TODAY(),Shifts!$B$2:$AE$2,0))"
    Range("AM27").FormulaArray = "=INDEX(Shifts!$B$5:$AE$35,MATCH('Day Plan'!B27,Shifts!$A$5:$A$35,0),MATCH(TODAY(),Shifts!$B$2:$AE$2,0))"
    Range("AM31").FormulaArray = "=INDEX(Shifts!$B$5:$AE$35,MATCH('Day Plan'!B31,Shifts!$A$5:$A$35,0),MATCH(TODAY(),Shifts!$B$2:$AE$2,0))"
    Range("AM32").FormulaArray = "=INDEX(Shifts!$B$5:$AE$35,MATCH('Day Plan'!B32,Shifts!$A$5:$A$35,0),MATCH(TODAY(),Shifts!$B$2:$AE$2,0))"
    Range("AM33").FormulaArray = "=INDEX(Shifts!$B$5:$AE$35,MATCH('Day Plan'!B33,Shifts!$A$5:$A$35,0),MATCH(TODAY(),Shifts!$B$2:$AE$2,0))"
    Range("AM34").FormulaArray = "=INDEX(Shifts!$B$5:$AE$35,MATCH('Day Plan'!B34,Shifts!$A$5:$A$35,0),MATCH(TODAY(),Shifts!$B$2:$AE$2,0))"
    Range("AM35").FormulaArray = "=INDEX(Shifts!$B$5:$AE$35,MATCH('Day Plan'!B35,Shifts!$A$5:$A$35,0),MATCH(TODAY(),Shifts!$B$2:$AE$2,0))"
    Range("AM36").FormulaArray = "=INDEX(Shifts!$B$5:$AE$35,MATCH('Day Plan'!B36,Shifts!$A$5:$A$35,0),MATCH(TODAY(),Shifts!$B$2:$AE$2,0))"
    Range("AM37").FormulaArray = "=INDEX(Shifts!$B$5:$AE$35,MATCH('Day Plan'!B37,Shifts!$A$5:$A$35,0),MATCH(TODAY(),Shifts!$B$2:$AE$2,0))"
    Range("AM38").FormulaArray = "=INDEX(Shifts!$B$5:$AE$35,MATCH('Day Plan'!B38,Shifts!$A$5:$A$35,0),MATCH(TODAY(),Shifts!$B$2:$AE$2,0))"
    Range("AM39").FormulaArray = "=INDEX(Shifts!$B$5:$AE$35,MATCH('Day Plan'!B39,Shifts!$A$5:$A$35,0),MATCH(TODAY(),Shifts!$B$2:$AE$2,0))"
    Range("AM40").FormulaArray = "=INDEX(Shifts!$B$5:$AE$35,MATCH('Day Plan'!B40,Shifts!$A$5:$A$35,0),MATCH(TODAY(),Shifts!$B$2:$AE$2,0))"
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,177
Members
453,021
Latest member
Justyna P

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