SOLVED

Excel If then else support

%3CLINGO-SUB%20id%3D%22lingo-sub-119783%22%20slang%3D%22en-US%22%3EExcel%20If%20then%20else%20support%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-119783%22%20slang%3D%22en-US%22%3E%3CP%3EHey%20everyone%2C%20I'm%20having%20trouble%20finding%20the%20right%20syntax%20for%20an%20excel%20if%2Felse%2Fthan%20formula%20in%20a%20spread%20sheet.%20I%20think%20I%20have%20all%20the%20individual%20parts%2C%20but%20putting%20it%20together%20is%20stumping%20me.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ELets%20say%20I%20have%20a%20date%20in%20cell%20A1%20and%20a%20value%20in%20A2.%20Cell%20A3%20calculates%20a%20new%20date%20based%20on%20A1%20minus%20A2.%20what%20I%20would%20like%20is%20to%20then%20say%20-%20If%20A3%20is%20Saturday%2C%20subtract%201%20more%20day%2C%20If%20A3%20is%20a%20Sunday%2C%20add%201%20more%20day.%20Then%20Highlight%20the%20cell%20so%20I%20know%20that%20the%20additional%20math%20adjustment%20was%20made.%20I%20know%20that%20I%20can%20use%20WEEKDAY%20%3D%207%20to%20find%20Saturday%2C%20and%20WEEKDAY%20%3D%201%20to%20find%20Sunday%20but%20putting%20it%20all%20together%20has%20proven%20difficult.%26nbsp%3B%20thanks%20for%20the%20help.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-119783%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EExcel%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-123721%22%20slang%3D%22en-US%22%3ERe%3A%20Excel%20If%20then%20else%20support%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-123721%22%20slang%3D%22en-US%22%3E%3CP%3E%40Vito%2C%3CBR%20%2F%3EFor%20the%20Add%2FSubtract%20formula%20-%20may%20I%20suggest%20the%20following%3A%3CBR%20%2F%3E%3CEM%3E%3CSTRONG%3E%3DA1-A2%2BCHOOSE(WEEKDAY(A1-A2)%2C1%2C%2C%2C%2C%2C%2C-1)%3CBR%20%2F%3E%3C%2FSTRONG%3E%3C%2FEM%3E%3C%2FP%3E%3CP%3E%3CSTRONG%3E--------------------------%3CBR%20%2F%3EMichael%20(Micky)%20Avidan%3C%2FSTRONG%3E%3CBR%20%2F%3E%3CEM%3E%E2%80%9CMicrosoft%C2%AE%20Answers%22%20-%20Wiki%20author%20%26amp%3B%20Forums%20Moderator%3CBR%20%2F%3E%3CSTRONG%3E%E2%80%9CMicrosoft%C2%AE%E2%80%9D%3C%2FSTRONG%3E%20%3CSTRONG%3EExcel%20MVP%20%E2%80%93%20Excel%20%3C%2FSTRONG%3E%3C%2FEM%3E%3CSTRONG%3E(2009-2018)%3CBR%20%2F%3E%3C%2FSTRONG%3EISRAEL%3C%2FP%3E%3CP%3E%3CEM%3E%3CSTRONG%3E%26nbsp%3B%3C%2FSTRONG%3E%3C%2FEM%3E%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-121036%22%20slang%3D%22en-US%22%3ERe%3A%20Excel%20If%20then%20else%20support%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-121036%22%20slang%3D%22en-US%22%3E%3CP%3EIngeborg%20-%20this%20is%20brilliantly%20elegant.%20Thank%20you%20so%20much.%20Exactly%20what%20I%20was%20trying%20to%20do.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-120142%22%20slang%3D%22en-US%22%3ERe%3A%20Excel%20If%20then%20else%20support%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-120142%22%20slang%3D%22en-US%22%3E%3CP%3EPerhaps%20no%20practical%20sense%2C%20just%20my%20exercise%20with%20%22no%20IF%22%20formula%3C%2FP%3E%3CPRE%3E%3DA1-A2%2BLOOKUP(MOD((A1-A2)%2F7%2C1)*7%2C%7B0%2C0.9%2C1.5%7D%2C%7B-1%2C1%2C0%7D)%3C%2FPRE%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-119895%22%20slang%3D%22en-US%22%3ERe%3A%20Excel%20If%20then%20else%20support%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-119895%22%20slang%3D%22en-US%22%3E%3CP%3EHello%2C%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3Eyou%20can%20use%20this%20formula%20in%20cell%20A3%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3DA1-A2%2BIF(WEEKDAY(A1-A2)%3D1%2C1%2CIF(WEEKDAY(A1-A2)%3D7%2C-1%2C0))%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThen%20you%20can%20use%20conditional%20formatting%20on%20cell%20A3%20with%20a%20rule%20that%20uses%20a%20formula.%20Either%20use%20one%20rule%20for%20both%20Saturday%20and%20Sunday%20adjustments%20with%20the%20formula%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3Dor(%3CSPAN%3EWEEKDAY(A1-A2)%3D1%2CWEEKDAY(A1-A2)%3D7)%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CSPAN%3Eor%20use%20one%20rule%20for%20Sunday%20with%20one%20color%2C%20and%20another%20rule%20for%20Saturday%20with%20another%20colour.%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%3CSPAN%3E%3DWEEKDAY(A1-A2)%3D1%26nbsp%3B%20%26nbsp%3B--%20sunday%20rule%2C%20use%20green%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%3CSPAN%3E%3DWEEKDAY(A1-A2)%3D7%26nbsp%3B%20--%20saturday%20rule%2C%20use%26nbsp%3Bred%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CSPAN%3EDoes%20that%20help%3F%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-119892%22%20slang%3D%22en-US%22%3ERe%3A%20Excel%20If%20then%20else%20support%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-119892%22%20slang%3D%22en-US%22%3E%3CP%3EHi%20Sergei%2C%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3Ethanks%20for%20pointing%20this%20out.%26nbsp%3BVito%2C%20to%26nbsp%3Bevaluate%20the%20resulting%20date%2C%20you%20can%20just%20add%20a%20reference%20to%20B1%20in%20your%20D1%20formula%2C%20so%20that%20it%20looks%20as%20follows%3A%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ENested%20IFs%3A%20%26nbsp%3B%3DIF(WEEKDAY(A1%2BB1%2C1)%3D7%2C-1%2CIF(WEEKDAY(A1%2BB1%2C1)%3D1%2C1%2C0))%3C%2FP%3E%3CP%3ESWITCH%3A%26nbsp%3B%3DSWITCH(WEEKDAY(A1%2BB1%2C1)%2C7%2C-1%2C1%2C1)%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThanks%3C%2FP%3E%3CP%3EYury%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-119886%22%20slang%3D%22en-US%22%3ERe%3A%20Excel%20If%20then%20else%20support%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-119886%22%20slang%3D%22en-US%22%3E%3CP%3EYury%2C%20IMHO%2C%20that's%20resulting%20date%20shall%20be%20checked%20on%20Sat%2FSun%2C%20not%20the%20start%20date%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-119880%22%20slang%3D%22en-US%22%3ERe%3A%20Excel%20If%20then%20else%20support%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-119880%22%20slang%3D%22en-US%22%3E%3CP%3EHi%20Vito%2C%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3Eyou%20can%20add%20an%20extra%20cell%20in%20D1%20to%20evaluate%20if%20A1%20value%20is%20Saturday%20or%20Sunday%2C%20and%20return%20-1%20or%201%26nbsp%3Brespectively.%20Your%20formula%20in%20D1%20can%20be%26nbsp%3B%3DIF(WEEKDAY(A1%2C1)%3D7%2C-1%2CIF(WEEKDAY(A1%3D1%2C1)%2C0)).%20If%20you%20are%20on%20Office365%2C%20a%20better%20alternative%20would%20be%20to%20use%20the%20SWITCH%20function.%20In%20this%20case%2C%20your%20formula%20in%20D1%20would%20be%26nbsp%3B%3DSWITCH(WEEKDAY(A1%2C1)%2C7%2C-1%2C1%2C1).%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ESubsequently%2C%20you%20can%20add%20the%20D1%26nbsp%3Breference%20to%20C1%2C%20so%20that%20the%20latter%20has%20'%3DA1-B1%2BD1'%2C%20then%20conditionally%20format%20it%20based%20on%20the%20value%20in%20D1%20(e.g.%20colour%20cell%20if%20D1%20is%20not%20equal%200).%20Please%20see%20attached%20for%20an%20example.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EHope%20this%20helps%3C%2FP%3E%3CP%3EYury%3C%2FP%3E%3C%2FLINGO-BODY%3E
New Contributor

Hey everyone, I'm having trouble finding the right syntax for an excel if/else/than formula in a spread sheet. I think I have all the individual parts, but putting it together is stumping me.

 

Lets say I have a date in cell A1 and a value in A2. Cell A3 calculates a new date based on A1 minus A2. what I would like is to then say - If A3 is Saturday, subtract 1 more day, If A3 is a Sunday, add 1 more day. Then Highlight the cell so I know that the additional math adjustment was made. I know that I can use WEEKDAY = 7 to find Saturday, and WEEKDAY = 1 to find Sunday but putting it all together has proven difficult.  thanks for the help.

7 Replies

Hi Vito,

 

you can add an extra cell in D1 to evaluate if A1 value is Saturday or Sunday, and return -1 or 1 respectively. Your formula in D1 can be =IF(WEEKDAY(A1,1)=7,-1,IF(WEEKDAY(A1=1,1),0)). If you are on Office365, a better alternative would be to use the SWITCH function. In this case, your formula in D1 would be =SWITCH(WEEKDAY(A1,1),7,-1,1,1).

 

Subsequently, you can add the D1 reference to C1, so that the latter has '=A1-B1+D1', then conditionally format it based on the value in D1 (e.g. colour cell if D1 is not equal 0). Please see attached for an example.

 

Hope this helps

Yury

Yury, IMHO, that's resulting date shall be checked on Sat/Sun, not the start date

Hi Sergei,

 

thanks for pointing this out. Vito, to evaluate the resulting date, you can just add a reference to B1 in your D1 formula, so that it looks as follows:

 

Nested IFs:  =IF(WEEKDAY(A1+B1,1)=7,-1,IF(WEEKDAY(A1+B1,1)=1,1,0))

SWITCH: =SWITCH(WEEKDAY(A1+B1,1),7,-1,1,1)

 

Thanks

Yury 

best response confirmed by Vito DiMercurio (New Contributor)
Solution

Hello,

 

you can use this formula in cell A3

 

=A1-A2+IF(WEEKDAY(A1-A2)=1,1,IF(WEEKDAY(A1-A2)=7,-1,0))

 

Then you can use conditional formatting on cell A3 with a rule that uses a formula. Either use one rule for both Saturday and Sunday adjustments with the formula

 

=or(WEEKDAY(A1-A2)=1,WEEKDAY(A1-A2)=7)

 

or use one rule for Sunday with one color, and another rule for Saturday with another colour.

=WEEKDAY(A1-A2)=1   -- sunday rule, use green

=WEEKDAY(A1-A2)=7  -- saturday rule, use red

 

Does that help?

 

Perhaps no practical sense, just my exercise with "no IF" formula

=A1-A2+LOOKUP(MOD((A1-A2)/7,1)*7,{0,0.9,1.5},{-1,1,0})

 

Ingeborg - this is brilliantly elegant. Thank you so much. Exactly what I was trying to do.

@Vito,
For the Add/Subtract formula - may I suggest the following:
=A1-A2+CHOOSE(WEEKDAY(A1-A2),1,,,,,,-1)

--------------------------
Michael (Micky) Avidan

“Microsoft® Answers" - Wiki author & Forums Moderator
“Microsoft®” Excel MVP – Excel
(2009-2018)
ISRAEL