Help with Hlookup, with Match specific/partial text, and possibly Small formula

dlmoore99

Board Regular
Joined
May 20, 2011
Messages
88
Office Version
  1. 2019
Platform
  1. MacOS
I've been Googling and trying many combinations that I've seen from multiple forums for a couple of weeks now, Now I'm going to the experts. Formula in E15, Once I match a date in J1 to the dates in column S, I'm trying to find the first cell in a row that contains the text "Holiday" and return that cell if True, if False (no cells that contain "Holiday" then return "". Then in E16 do the same but for the second cell that contains "Holiday" in the same row. ie, Formula in E15: if Date in J1 is 01/13/23 and matched the Date in S14, the first cell that contains "Holiday" is X14 (C006 Holiday), then return X14 to E15. The formula in E16 will do the same but look for the second cell that contains "Holiday" AC14 (C012 Holiday) and return it to E16. I've tried many things from =INDEX(T14:AF14,MATCH(TRUE,INDEX(ISTEXT(T14:AF14),0),0)), but that returns the first cell with text T14 (C001). This works =HLOOKUP("*H*",$T$14:$AF$14,1,FALSE) to find the first cell with "Holiday" but doesn't have the Date Match, nor how to get the second "Holiday" match in the row, Not sure if a Small function or what is needed. Thank you for your help.



Carrier Schedule.xlsx
STUVWXYZAAABACADAEAF
121/11/24C007C009C011
131/12/24C001C010C026
141/13/24C001C006 HolidayC010C012 HolidayC026
151/14/24
161/15/24
LACONIA
 
Well, tell us what you actually need.
(BTW, It doesn't need to be either AhoyNC or me to answer - anybody might be able to help :))
 
Upvote 0

Excel Facts

Bring active cell back into view
Start at A1 and select to A9999 while writing a formula, you can't see A1 anymore. Press Ctrl+Backspace to bring active cell into view.
I added more of my spreadsheet so you can see what I'm for got. I need to incorporate the formula I asked for the the original post with the formula I have in E3:E14. As you can see in the spreadsheet that TYO appears twice E3 and E6 when E6 should say C006 Holiday, Same goes for PRICE in E10 and E12 (E12 should be C012 Holiday. I hope I'm explaining it well enough. It's way past my bed time.

Carrier Schedule.xlsx
ABCDEFGHIJKLMNOPQRSTUVWXYZAAABACADAEAF
1Sat01/13/2024NameRTEDateC001C002C004C005C006C007C009C010C011C012C013C026T6
2Route #A/LS/LOtherNameOTU-SETS123456FOOTEC0011/1/24
3C001TYOPRICE9101252NSBRUNELLEC0021/2/24T6
4C002BRUNELLETYO1116134NSANDERSONC0041/3/24C007C009C011
5C004ANDERSONNon T6 Routes726MOOREC0051/4/24C001C010C026
6C005MOOREJON - MEDICALTAVANOC0061/5/24C006C012
7C006TYOPTF'SFINNIGANC0071/6/24C006C012
8C007FINNIGANDamianOLINGERC0091/7/24
9C009OLINGERMeridethDOREC0101/8/24C005C013
10C010PRICEAimeeHUMEC0111/9/24C002C004
11C011HUMEMikePETERSC0121/10/24T6
12C012PRICECARMAGANIC0131/11/24C007C009C011
13C013CARMAGANICOLLECTIONS:TARBELEC0261/12/24C001C010C026
14C026PTF:All:PRICET61/13/24C001C006 HolidayC010C012 HolidayC026
15 C006 HolidayOutside:TYOT61/14/24
16C012 HolidayDowntown:1/15/24
17 1/16/24C005C013
18Run:1/17/24C002C004
191/18/24T6
201/19/24C007C009C011
21Sun01/14/2024US HolidaysHoliday Name1/20/24C007C009C011
22Route #A/LS/LOtherNameOTU-SETS12345601-Jan-24New Year's1/21/24
LACONIA
Cell Formulas
RangeFormula
H1,H21H1=TEXT(J1, "ddd")
E3E3=IF(COUNTIF(Table4[US Holidays],$J$1),"Holiday",IF(INDEX($T$2:$T$732,MATCH($J$1,$S$2:$S$732,0))="",INDEX($P$2:$P$18,MATCH($A3,$Q$2:$Q$18,0)),"TYO"))
E4E4=IF(COUNTIF(Table4[US Holidays],$J$1),"Holiday",IF(INDEX($U$2:$U$732,MATCH($J$1,$S$2:$S$732,0))="",INDEX($P$2:$P$18,MATCH($A4,$Q$2:$Q$18,0)),"PRICE"))
E5E5=IF(COUNTIF(Table4[US Holidays],$J$1),"Holiday",IF(INDEX($V$2:$V$732,MATCH($J$1,$S$2:$S$732,0))="",INDEX($P$2:$P$18,MATCH($A5,$Q$2:$Q$18,0)),"TYO"))
E6E6=IF(COUNTIF(Table4[US Holidays],$J$1),"Holiday",IF(INDEX($W$2:$W$732,MATCH($J$1,$S$2:$S$732,0))="",INDEX($P$2:$P$18,MATCH($A6,$Q$2:$Q$18,0)),"PRICE"))
E7E7=IF(COUNTIF(Table4[US Holidays],$J$1),"Holiday",IF(INDEX($X$2:$X$732,MATCH($J$1,$S$2:$S$732,0))="",INDEX($P$2:$P$18,MATCH($A7,$Q$2:$Q$18,0)),"TYO"))
E8E8=IF(COUNTIF(Table4[US Holidays],$J$1),"Holiday",IF(INDEX($Y$2:$Y$732,MATCH($J$1,$S$2:$S$732,0))="",INDEX($P$2:$P$18,MATCH($A8,$Q$2:$Q$18,0)),"PTF:"))
E9E9=IF(COUNTIF(Table4[US Holidays],$J$1),"Holiday",IF(INDEX($Z$2:$Z$732,MATCH($J$1,$S$2:$S$732,0))="",INDEX($P$2:$P$18,MATCH($A9,$Q$2:$Q$18,0)),"PRICE"))
E10E10=IF(COUNTIF(Table4[US Holidays],$J$1),"Holiday",IF(INDEX($AA$2:$AA$732,MATCH($J$1,$S$2:$S$732,0))="",INDEX($P$2:$P$18,MATCH($A10,$Q$2:$Q$18,0)),"PRICE"))
E11E11=IF(COUNTIF(Table4[US Holidays],$J$1),"Holiday",IF(INDEX($AB$2:$AB$732,MATCH($J$1,$S$2:$S$732,0))="",INDEX($P$2:$P$18,MATCH($A11,$Q$2:$Q$18,0)),"TYO"))
E12E12=IF(COUNTIF(Table4[US Holidays],$J$1),"Holiday",IF(INDEX($AC$2:$AC$732,MATCH($J$1,$S$2:$S$732,0))="",INDEX($P$2:$P$18,MATCH($A12,$Q$2:$Q$18,0)),"PRICE"))
E13E13=IF(COUNTIF(Table4[US Holidays],$J$1),"Holiday",IF(INDEX($AD$2:$AD$732,MATCH($J$1,$S$2:$S$732,0))="",INDEX($P$2:$P$18,MATCH($A13,$Q$2:$Q$18,0)),"TYO"))
E14E14=IF(COUNTIF(Table4[US Holidays],$J$1),"Holiday",IF(INDEX($AE$2:$AE$732,MATCH($J$1,$S$2:$S$732,0))="",INDEX($P$2:$P$18,MATCH($A14,$Q$2:$Q$18,0)),"PTF:"))
E15:E17E15=IFERROR(INDEX(INDEX($T$2:$AF$732,MATCH($J$1,$S$2:$S$732,0),0),AGGREGATE(15,6,(COLUMN($T$2:$AF$2)-COLUMN($T$2)+1)/(ISNUMBER(SEARCH("Holiday"," "&INDEX($T$2:$AF$732,MATCH($J$1,$S$2:$S$732,0),0)&" "))),ROWS($E$15:$E15))),"")
J21J21=($J$1+1)
Named Ranges
NameRefers ToCells
_C001=LACONIA!$Q$3:$Q$18E3:E14
Name=LACONIA!$P$2:$P$15E3:E14
Cells with Conditional Formatting
CellConditionCell FormatStop If True
H2Expression=WEEKDAY($J$1)=2textNO
I2Expression=WEEKDAY($J$1)=3textNO
J2Expression=WEEKDAY($J$1)=4textNO
K2Expression=WEEKDAY($J$1)=5textNO
L2Expression=WEEKDAY($J$1)=6textNO
M2Expression=WEEKDAY($J$1)=7textNO
H22Expression=WEEKDAY($J$21)=2textNO
I22Expression=WEEKDAY($J$21)=3textNO
J22Expression=WEEKDAY($J$21)=4textNO
K22Expression=WEEKDAY($J$21)=5textNO
L22Expression=WEEKDAY($J$21)=6textNO
M22Expression=WEEKDAY($J$21)=7textNO
 
Upvote 0
  1. I don't see any logic re the 'fall-back' values of "TYO", "PRICE" & "PTF:" so that leads to a rather messy mix of different formulas down column E - but that is what you had anyway. :eek:

  2. I don't know what your table names are apart from 'Table4' being the small holiday one in P21:Q22. In my sample below the table in P1:Q18 is 'Table2' and the one in S1:AF22 is 'Table5'If my formulas are what you want, you will need to either adjust the table names in all the formulas or else rearrange your table names to match mine.
See if this is what you want.
Rather than trying to put all the different formulas into column E it might be easier to copy E3 all the way down and then just swap "TYO" to "PRICE" or "PTF:" in the relevant rows since that is the only difference between the various formulas.

dlmoore99.xlsm
AEJOPQRSTUVWXYZAAABACADAEAF
113/01/2024NameRTEDateC001C002C004C005C006C007C009C010C011C012C013C026T6
2Route #Name3FOOTEC0011/01/2024
3C001TYO12BRUNELLEC0022/01/2024T6
4C002BRUNELLE6ANDERSONC0043/01/2024C007C009C011
5C004ANDERSONMOOREC0054/01/2024C001C010C026
6C005MOORETAVANOC0065/01/2024C006C012
7C006C006 HolidayFINNIGANC0076/01/2024C006C012
8C007FINNIGANOLINGERC0097/01/2024
9C009OLINGERDOREC0108/01/2024C005C013
10C010PRICEHUMEC0119/01/2024C002C004
11C011HUMEPETERSC01210/01/2024T6
12C012C012 HolidayCARMAGANIC01311/01/2024C007C009C011
13C013CARMAGANITARBELEC02612/01/2024C001C010C026
14C026PTF:PRICET613/01/2024C001C006 HolidayC010C012 HolidayC026
15 TYOT614/01/2024
1615/01/2024
1716/01/2024C005C013
1817/01/2024C002C004
1918/01/2024T6
2019/01/2024C007C009C011
21US HolidaysHoliday Name20/01/2024C007C009C011
22Route #Name31/01/2024New Year's21/01/2024
23
Sheet2
Cell Formulas
RangeFormula
E3,E5,E7,E11,E13E3=IF(COUNTIF(Table4[US Holidays],$J$1),"Holiday",IF(INDEX(Table5,MATCH(J$1,Table5[Date],0),MATCH(A3,Table5[#Headers],0))="",INDEX(Table2[Name],MATCH(A3,Table2[RTE],0),1),IF(INDEX(Table5,MATCH(J$1,Table5[Date],0),MATCH(A3,Table5[#Headers],0))=A3,"TYO",INDEX(Table5,MATCH(J$1,Table5[Date],0),MATCH(A3,Table5[#Headers],0)))))
E4,E6,E9:E10,E12E4=IF(COUNTIF(Table4[US Holidays],$J$1),"Holiday",IF(INDEX(Table5,MATCH(J$1,Table5[Date],0),MATCH(A4,Table5[#Headers],0))="",INDEX(Table2[Name],MATCH(A4,Table2[RTE],0),1),IF(INDEX(Table5,MATCH(J$1,Table5[Date],0),MATCH(A4,Table5[#Headers],0))=A4,"PRICE",INDEX(Table5,MATCH(J$1,Table5[Date],0),MATCH(A4,Table5[#Headers],0)))))
E8,E14E8=IF(COUNTIF(Table4[US Holidays],$J$1),"Holiday",IF(INDEX(Table5,MATCH(J$1,Table5[Date],0),MATCH(A8,Table5[#Headers],0))="",INDEX(Table2[Name],MATCH(A8,Table2[RTE],0),1),IF(INDEX(Table5,MATCH(J$1,Table5[Date],0),MATCH(A8,Table5[#Headers],0))=A8,"PTF:",INDEX(Table5,MATCH(J$1,Table5[Date],0),MATCH(A8,Table5[#Headers],0)))))
 
Upvote 0
In regards to the 'fall-back' values of "TYO", "PRICE" & "PTF:", they are the people who will cover certain routes. Price will cover the routes in G3:M3, TYO will cover the routes in G4:M4, PTF's will cover things not covered by PRICE & TYO. The spaces are small in G3:M5, so I didn't use the full route names found in A3:A14. PTF's, G8:G11 don't have a set daily work schedule and names are written in E3:E14 on a daily basis to cover whatever needs to be covered. Would it be better to create another table for Price & Tyo for the routes they cover. Table 2 T3:AF732 contains the routes Day off and that will be covered by either Price or Tyo. Not sure how to explain it better. Would I be better if I put the names in Table 2 T3:AF732, and somehow Index/Match instead of looking for blanks. I would still need the Holiday part in the original post.
 
Upvote 0
Not sure that I understand all of that but I think adding a lookup table to get TYP/PRICE etc would be a good idea. I have attempted that in P24:Q34 below and then a single formula can be copied down column E. Is that any better?
BTW, I have copied my previous sheet so the table names have changed
P:Q top table is Table27
P:Q middle table (holidays) is Table48
P:Q bottom table (new table) is tblCover
S:AF table is Table 59
You will have to adjust my formula to match your table names.

dlmoore99.xlsm
AEJOPQRSTUVWXYZAAABACADAEAF
113/01/2024NameRTEDateC001C002C004C005C006C007C009C010C011C012C013C026T6
2Route #NameFOOTEC0011/01/2024
3C001TYOBRUNELLEC0022/01/2024T6
4C002BRUNELLEANDERSONC0043/01/2024C007C009C011
5C004ANDERSONMOOREC0054/01/2024C001C010C026
6C005MOORETAVANOC0065/01/2024C006C012
7C006C006 HolidayFINNIGANC0076/01/2024C006C012
8C007FINNIGANOLINGERC0097/01/2024
9C009OLINGERDOREC0108/01/2024C005C013
10C010PRICEHUMEC0119/01/2024C002C004
11C011HUMEPETERSC01210/01/2024T6
12C012C012 HolidayCARMAGANIC01311/01/2024C007C009C011
13C013CARMAGANITARBELEC02612/01/2024C001C010C026
14C026PTF:PRICET613/01/2024C001C006 HolidayC010C012 HolidayC026
15 TYOT614/01/2024
1615/01/2024
1716/01/2024C005C013
1817/01/2024C002C004
1918/01/2024T6
2019/01/2024C007C009C011
21US HolidaysHoliday Name20/01/2024C007C009C011
22Route #Name31/01/2024New Year's21/01/2024
23
24RouteCover
25C001TYO
26C002PRICE
27C004TYO
28C005PRICE
29C006TYO
30C009PRICE
31C010PRICE
32C011TYO
33C012PRICE
34C013TYO
35
Sheet3
Cell Formulas
RangeFormula
E3:E14E3=IF(COUNTIF(Table48[US Holidays],$J$1),"Holiday",IF(INDEX(Table59,MATCH(J$1,Table59[Date],0),MATCH(A3,Table59[#Headers],0))="",INDEX(Table27[Name],MATCH(A3,Table27[RTE],0),1),IF(INDEX(Table59,MATCH(J$1,Table59[Date],0),MATCH(A3,Table59[#Headers],0))=A3,IFNA(VLOOKUP(A3,tblCover,2,0),"PTF:"),INDEX(Table59,MATCH(J$1,Table59[Date],0),MATCH(A3,Table59[#Headers],0)))))
 
Upvote 0
That works great, What if I just add the PTF and the 2 routes C007 & C026 to the cover table and adjust the IF statement. Wouldn't that make formula shorter?
 
Upvote 0
That works great, What if I just add the PTF and the 2 routes C007 & C026 to the cover table and adjust the IF statement. Wouldn't that make formula shorter?
Sure, if they are two fixed substitutions. It's just that the following sounded to me like "PTF:" was yet another fall-back position
In regards to the 'fall-back' values of "TYO", "PRICE" & "PTF:", they are the people who will cover certain routes. Price will cover the routes in G3:M3, TYO will cover the routes in G4:M4, PTF's will cover things not covered by PRICE & TYO.

The formula only gets marginally shorter though. :)

dlmoore99.xlsm
AEJOPQRSTUVWXYZAAABACADAEAF
113/01/2024NameRTEDateC001C002C004C005C006C007C009C010C011C012C013C026T6
2Route #NameFOOTEC0011/01/2024
3C001TYOBRUNELLEC0022/01/2024T6
4C002BRUNELLEANDERSONC0043/01/2024C007C009C011
5C004ANDERSONMOOREC0054/01/2024C001C010C026
6C005MOORETAVANOC0065/01/2024C006C012
7C006C006 HolidayFINNIGANC0076/01/2024C006C012
8C007FINNIGANOLINGERC0097/01/2024
9C009OLINGERDOREC0108/01/2024C005C013
10C010PRICEHUMEC0119/01/2024C002C004
11C011HUMEPETERSC01210/01/2024T6
12C012C012 HolidayCARMAGANIC01311/01/2024C007C009C011
13C013CARMAGANITARBELEC02612/01/2024C001C010C026
14C026PTF:PRICET613/01/2024C001C006 HolidayC010C012 HolidayC026
15 TYOT614/01/2024
1615/01/2024
1716/01/2024C005C013
1817/01/2024C002C004
1918/01/2024T6
2019/01/2024C007C009C011
21US HolidaysHoliday Name20/01/2024C007C009C011
22Route #Name31/01/2024New Year's21/01/2024
23
24RouteCover
25C001TYO
26C002PRICE
27C004TYO
28C005PRICE
29C006TYO
30C009PRICE
31C010PRICE
32C011TYO
33C012PRICE
34C013TYO
35C007PTF:
36C026PTF:
Sheet3
Cell Formulas
RangeFormula
E3:E14E3=IF(COUNTIF(Table48[US Holidays],$J$1),"Holiday",IF(INDEX(Table59,MATCH(J$1,Table59[Date],0),MATCH(A3,Table59[#Headers],0))="",INDEX(Table27[Name],MATCH(A3,Table27[RTE],0),1),IF(INDEX(Table59,MATCH(J$1,Table59[Date],0),MATCH(A3,Table59[#Headers],0))=A3,VLOOKUP(A3,tblCover,2,0),INDEX(Table59,MATCH(J$1,Table59[Date],0),MATCH(A3,Table59[#Headers],0)))))
 
Upvote 0

Forum statistics

Threads
1,223,886
Messages
6,175,196
Members
452,616
Latest member
intern444

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