简体   繁体   中英

Excel - Lookup - Multiple result across multiple worksheets

Im doing a work calendar, that should be filled automatically depending of the day of the week or of the day of the month. Meaning:

I have weekly chores (each are equally every week) and monthly chores (each are equally for every specific work day of the month).

The idea is every time i change the month of the calendar, is filled with the chores needed to be done for each day.

This is the calendar that i'm doing (the red cells are filled by hand, the rest is automatically filled with the formula below): Calendar

Week Chores sheet Sheet ToDos week

Month Chores sheet Sheet ToDos Month

I already filled the weekly chores automatically with:

=IFERROR(INDEX('ToDos Week'!$C$3:$C$98;SMALL(IF((WEEKDAY($C$3;2)='ToDos Week'!$B$3:$B$98);ROW('ToDos Week'!$B$3:$B$98)-MIN(ROW('ToDos Week'!$B$3:$B$98))+1;"");ROWS($L$1:L3)));"")

Works like a charm

But my difficulty now is to add the monthly chores

I Tried to add

=IFERROR(IFERROR(INDEX('ToDos Week'!$C$3:$C$98;SMALL(IF((WEEKDAY($F$3;2)='ToDos Week'!$B$3:$B$98);ROW('ToDos Week'!$B$3:$B$98)-MIN(ROW('ToDos Week'!$B$3:$B$98))+1;"");ROWS($L$1:L1)));INDEX('ToDos Month'!$C$3:$C$91;SMALL(IF((NETWORKDAYS(F$5-DAY(F$5)+1;F$5;holidays)='ToDos Month'!$B$3:$B$91);ROW('ToDos Month'!$B$3:$B$91)-MIN(ROW('ToDos Month'!$B$3:$B$91))+1;"");ROWS($L$1:L1))));"")

of course doesn't work because the part "ROWS($L$1:L1)" of the formula will stretch and will not give me the first occurrence of the month chores (in case there's week chores in the same day), but the third or fourth..

Can you help me with this?

{Big Edit} Okay, I've just realised I overlooked a really simple solution - as demonstrated in an earlied edit, we can use COUNTIF to get the number of Daily Tasks for the weekday. So, we can subtract this from the Monthly Task count to correct the number.

To Simplify: Is the task Weekly or Monthly? (You may need to add/subtract from ROWS to get it to line up)

=IF(COUNTIF('ToDos Week'!$B$3:$B$98,WEEKDAY($C$3,2))>=ROWS($L$1:L3), "Weekly", "Monthly")

Use your existing code for Weekly. For Monthly, just subtract COUNTIF('ToDos Week'!$B$3:$B$98,WEEKDAY($C$3,2)) from the ROWS to remove all the Weekly tasks:

IFERROR(INDEX('ToDos Month'!$B$3:$B$98;SMALL(IF((DAY($C$3;2)='ToDos Month'!$A$3:$A$98);ROW('ToDos Month'!$A$3:$A$98)-MIN(ROW('ToDos Month'!$A$3:$A$98))+1;"");ROWS($L$1:L3)))-COUNTIF('ToDos Week'!$B$3:$B$98,WEEKDAY(C$3,2))>=ROWS($L$1:L3);"")

Replace the "Weekly" and "Monthly" in the IF above, and you get:

=IF(COUNTIF('ToDos Month'!$B$3:$B$98,WEEKDAY(C$3,2))>=ROWS($L$1:L3),IFERROR(INDEX('ToDos Week'!$C$3:$C$98;SMALL(IF((WEEKDAY($C$3;2)='ToDos Week'!$B$3:$B$98);ROW('ToDos Week'!$B$3:$B$98)-MIN(ROW('ToDos Week'!$B$3:$B$98))+1;"");ROWS($L$1:L3)));""),IFERROR(INDEX('ToDos Month'!$B$3:$B$98;SMALL(IF((DAY($C$3;2)='ToDos Month'!$A$3:$A$98);ROW('ToDos Month'!$A$3:$A$98)-MIN(ROW('ToDos Month'!$A$3:$A$98))+1;"");ROWS($L$1:L3)))-COUNTIF('ToDos Week'!$B$3:$B$98,WEEKDAY(C$3,2))>=ROWS($L$1:L3);""))

Old answer below


Okay, there are 2 possible solutions I can think of here... The first, and simplest, only works if your Weekly Tasks and Monthly Tasks are formatted differently (eg Monthly tasks may all start "[M]", such as "[M]File Invoices") In that case, replace the ROWS(L$1:L3) with a COUNTIF to count the Monthly tasks (eg COUNTIF(L$1:L3;"[M]*") )

If you have no 'easy' way to check weekly/monthly, the next option would be to use a SUM in the Array Formula to compare each entry in $L1:L3 against the ToDos Month list (eg SUM(COUNTIF('ToDos Month'!$B$3:$B$91;L$1:L3)) , taking advantage of the fact that a COUNTIF where both arguments are arrays will itself return an array)

These 2 options should give you the number of Monthly tasks in your day, for the k of your SMALL function

{EDIT:Removing the 'blank' column} This needs redoing for each week/row. It is based on my test sheet, where cell A14 was 05/02/2018, E14 was 09/02/2018 and the array formula was put into A15 and filled down-and-right to E23

=IF(COUNTIF('ToDos Week'!$B$3:$B$98,WEEKDAY(A$14,2))>=ROWS(A$14:A14),IFERROR(INDEX('ToDos Week'!$C$3:$C$98,SMALL(IF((WEEKDAY(A$14,2)='ToDos Week'!$B$3:$B$98),ROW('ToDos Week'!$B$3:$B$98)-MIN(ROW('ToDos Week'!$B$3:$B$98))+1,""),ROWS(A$14:A14))),""),IFERROR(INDEX('ToDos Month'!$B$3:$B$98,SMALL(IF((DAY(A$14)='ToDos Month'!$A$3:$A$98),ROW('ToDos Month'!$A$3:$A$98)-MIN(ROW('ToDos Month'!$A$3:$A$98))+1,""),COUNTIF(A$14:A14,"Month*")+1)),""))

First thing it does it check how many Weekly tasks there are for the day. If this is greater than the number of tasks already filled out, it looks for a Weekly task, otherwise it looks to a Monthly task - counting the existing Monthly tasks as starting with "Month"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM