IIF for Criteria

Pestomania

Board Regular
Joined
May 30, 2018
Messages
160
Office Version
  1. 2013
Platform
  1. Windows
Hi! I am trying to use an IIF to determine the day of the week. And then it should return different dates. Here is my problem:

If today is Monday, return Monday - Friday of last week. If today is not Monday, return Monday - Now of this week. Below is the code I have tried using:


Code:
IIF ( WEEKDAY(NOW())=2, (NOW()-7 AND NOW()-6 AND NOW()-5 AND NOW()-4 AND NOW()-3), (NOW()+8-WEEKDAY(NOW())-6 AND NOW()+8-WEEKDAY(NOW())-5 AND NOW()+8-WEEKDAY(NOW())-4 AND NOW()+8-WEEKDAY(NOW())-3 AND NOW()+8-WEEKDAY(NOW())-2))


If I am making this more difficult than necessary, please let me know.
 
Last edited:

Excel Facts

Format cells as time
Select range and press Ctrl+Shift+2 to format cells as time. (Shift 2 is the @ sign).

Joe4

MrExcel MVP, Junior Admin
Joined
Aug 1, 2002
Messages
63,315
Office Version
  1. 365
Platform
  1. Windows
Try this for the Criteria:
Code:
Between IIf(Weekday(Date(),2)=1,Date()-7,Date()-Weekday(Date(),2)+1) and IIf(Weekday(Date(),2)=1,Date()-3,Date()-Weekday(Date(),2)+5)
 

Yongle

Well-known Member
Joined
Mar 11, 2015
Messages
6,977
Office Version
  1. 365
Platform
  1. Windows
Code:
Sub GetDates()
    Dim D As Date, fromDate As Date, toDate As Date, aDate As Date, msg As String
    D = Date
'range of dates
    fromDate = IIf(Weekday(D) = 2, D - 7, D - ((D - 2) Mod 7))
    toDate = IIf(Weekday(D) = 2, D - 3, D)
'get values
    msg = fromDate & " - " & toDate & vbCr & vbCr
        For aDate = fromDate To toDate
            msg = msg & vbCr & aDate
        Next
    MsgBox msg
End Sub
 
Master Excel Bundle

Excel contains over 450 functions, with more added every year. That’s a huge number, so where should you start? Right here with this bundle.

Forum statistics

Threads
1,164,282
Messages
5,836,400
Members
430,425
Latest member
xlsee

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
Top