Identify Fridays and long weekends

rollingzep

Board Regular
Joined
Nov 18, 2013
Messages
214
Office Version
  1. 365
Platform
  1. Windows
Hi,

In my Excel application, I need to set a value of a field, RWA based on another field, report date (RPT_DT) falling on Fridays or on long weekends.
If RPT_DT falls on Fridays, the value of RWA is 3 and if RPT_DT falls on long weekends, the RWA value is 4. For a midweek holiday it will be 2, and otherwise it will be a 1.

Can Excel's inbuilt function, NetworkDays be used and if so how in the above case?

TIA
 

Excel Facts

Who is Mr Spreadsheet?
Author John Walkenbach was Mr Spreadsheet until his retirement in June 2019.
Your would be better using NETWORKDAYS.INTL. In this function you can specify holidays. Are you able to post some data?
 
Upvote 0
Your would be better using NETWORKDAYS.INTL. In this function you can specify holidays. Are you able to post some data?
For Example, 12/30/2022 the RPT_DT was a Friday, but 01/31/2023 was a Tuesday. So, how to identify if the last working day of the month was a Friday or a weekday?
 
Upvote 0
If you just want to check if the week day is a Friday, then below should do the job
Book1.xlsx
BC
230/12/2022TRUE
Sheet4
Cell Formulas
RangeFormula
C2C2=IF(WEEKDAY(B2,11)=5,TRUE,FALSE)
 
Upvote 0
If you just want to check if the week day is a Friday, then below should do the job
Book1.xlsx
BC
230/12/2022TRUE
Sheet4
Cell Formulas
RangeFormula
C2C2=IF(WEEKDAY(B2,11)=5,TRUE,FALSE)
I get an error on the highlighted code

VBA Code:
LastRow = ws.Range("A" & Rows.Count).End(xlUp).Row
    For i = 2 To LastRow
        [B]If (Weekday(ws.Range("B" & i, 11) = 5, True, False)) = True Then[/B]
            ws.Range("BG" & i).Value = DateDiff("D", ws.Range("B" & i), ws.Range("AY" & i)) - 1
        End If
    Next i

If it is "True", then value of BG should be one day less than DateDiff("D", ws.Range("B" & i), ws.Range("AY" & i))

How to do this?
 
Upvote 0
You dont need the [B} and [/B]

Try the below
LastRow = ws.Range("A" & Rows.Count).End(xlUp).Row
For i = 2 To LastRow
If (Weekday(ws.Range("B" & i).Value, 11) = 5 Then
ws.Range("BG" & i).Value = DateDiff("D", ws.Range("B" & i), ws.Range("AY" & i)) - 1
End If
Next i
 
Upvote 0
You dont need the [B} and [/B]

Try the below
LastRow = ws.Range("A" & Rows.Count).End(xlUp).Row
For i = 2 To LastRow
If (Weekday(ws.Range("B" & i).Value, 11) = 5 Then
ws.Range("BG" & i).Value = DateDiff("D", ws.Range("B" & i), ws.Range("AY" & i)) - 1
End If
Next i
I have the date col format as 2023-01-31 00:00:00 and I get an error "invalid procedure call or argument on line 3

VBA Code:
    'Check for Fridays
    LastRow = ws.Range("A" & Rows.Count).End(xlUp).Row
    For i = 2 To LastRow
        If (Weekday(ws.Range("B" & i).Value, 11) = 5) Then
            ws.Range("BG" & i).Value = DateDiff("D", ws.Range("B" & i), ws.Range("AY" & i)) - 1
        End If
    Next i
 
Upvote 0
VBA Code:
'Check for Fridays
    LastRow = ws.Range("A" & Rows.Count).End(xlUp).Row
    For i = 2 To LastRow
        If (Weekday(INT(ws.Range("B" & i).Value), 11) = 5) Then
            ws.Range("BG" & i).Value = DateDiff("D", ws.Range("B" & i), ws.Range("AY" & i)) - 1
        End If
    Next i
 
Last edited by a moderator:
Upvote 0
VBA Code:
'Check for Fridays
    LastRow = ws.Range("A" & Rows.Count).End(xlUp).Row
    For i = 2 To LastRow
        If (Weekday(INT(ws.Range("B" & i).Value), 11) = 5) Then
            ws.Range("BG" & i).Value = DateDiff("D", ws.Range("B" & i), ws.Range("AY" & i)) - 1
        End If
    Next i
Now getting Type mismatch on this line

If (Weekday(INT(ws.Range("B" & i).Value), 11) = 5) Then

The col B is Text. And so is col AY. Should i change the format to date?
 
Upvote 0

Forum statistics

Threads
1,215,459
Messages
6,124,948
Members
449,198
Latest member
MhammadishaqKhan

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