Check for every Friday of the week.

donlincolnmre2

Board Regular
Joined
Dec 23, 2006
Messages
142
Hello

I’m looking to modify this macro which shows the date on upcoming Friday so in this case it will be 04/01/22

What I’m looking for is to place this Friday date in Cell A1 and then the macro will check every day for that day, so e.g if today is Tuesday and Friday is in future then the macro will just abort so same thing with wed and Thursday and If Friday is = to Friday then macro should also abort.

Once its Sat then the date in cell A1 is for Friday so the macro should put the new upcoming Friday date and keep checking as above for each day.

Below is the code.

Any help would be greatly appreciated.

Thanks.

Sub VBA_Find_Next_Friday_Method1()

Dim dNext_Friday As Date

dNext_Friday = DateAdd("d", -Weekday(Now) + 13, Now)

MsgBox "If today's date is '" & Format(Now, "DD MMM YYYY") & "' then" & vbCrLf & _
" Next Friday Date is : " & Format(dNext_Friday, "DD MMM YYYY"), vbInformation, "Next Friday Date"

End Sub
 

Excel Facts

Round to nearest half hour?
Use =MROUND(A2,"0:30") to round to nearest half hour. Use =CEILING(A2,"0:30") to round to next half hour.
VBA Code:
Sub VBA_Find_Next_Friday_Method1()
  
    For i = 1 To 14
          mydate = Date + i
          weekdag = Weekday(mydate, vbFriday)                   'weekday when the week starts on friday
          dNext_Friday = mydate + IIf(weekdag = 1, 0, (8 - weekdag))
          MsgBox "if today is " & Format(mydate, "ddd dd mm yyyy") & vbLf & " then next friday is " & Format(dNext_Friday, "ddd dd/mm/yyyy")
     Next
    
End Sub
Add 7 to dNext_Friday is it has to be 1 week later
 
Upvote 0
Rather than a macro you could just put this in A1 & it will show next Friday's date
Excel Formula:
=WORKDAY.INTL(TODAY()-1,1,"1111011")
 
Upvote 0
=WORKDAY.INTL(TODAY()-1,1,"1111011")

Above formula is not working,


VBA Code:
Sub VBA_Find_Next_Friday_Method1()
 
    For i = 1 To 14
          mydate = Date + i
          weekdag = Weekday(mydate, vbFriday)                   'weekday when the week starts on friday
          dNext_Friday = mydate + IIf(weekdag = 1, 0, (8 - weekdag))
          MsgBox "if today is " & Format(mydate, "ddd dd mm yyyy") & vbLf & " then next friday is " & Format(dNext_Friday, "ddd dd/mm/yyyy")
     Next
   
End Sub
Add 7 to dNext_Friday is it has to be 1 week later
Hello

I ran the macro and its showing the date in a TEXT BOX, instead of PUTTING VALUE IN CELL A1, (which will be Friday Date), my computer clock shows today is 3/25 but macro is saying if today is sat 26 03 2022 and there is a bug in there.

Since i'm doing some calculation base on Friday, then that Friday date has to be in cell A1 and then i can write calculations on it. Below is what i posted earlier.

What I’m looking for is to place this Friday date in Cell A1 and then the macro will check every day for that day, so e.g if today is Tuesday and Friday is in future then the macro will just abort so same thing with wed and Thursday and If Friday is = to Friday then macro should also abort.

Once its Sat then the date in cell A1 is for Friday so the macro should put the new upcoming Friday date and keep checking as above for each day.

Attached is a picture that shows when i ran the macro today which is FRIDAY, then it showing me wrong information.

Thanks.

1648231825138.png
 
Upvote 0
Cell Formulas
RangeFormula
B1B1=TODAY()
A1A1=next_Friday(B1)
A2A2=WORKDAY.INTL(B1-1,1,"1111011")

VBA Code:
Sub VBA_Find_Next_Friday_Method1()

     Dim dNext_Friday As Date

     dNext_Friday = Next_Friday(Now)

     MsgBox "If today's date is '" & Format(Now, "DD MMM YYYY") & "' then" & vbCrLf & " Next Friday Date is : " & Format(dNext_Friday, "DD MMM YYYY"), vbInformation, "Next Friday Date"

End Sub

Function Next_Friday(MyDate)
     weekdag = Weekday(MyDate, vbFriday)                        'weekday when the week starts on friday
     Next_Friday = MyDate + IIf(weekdag = 1, 0, (8 - weekdag))
End Function
 
Upvote 0
Cell Formulas
RangeFormula
B1B1=TODAY()
A1A1=next_Friday(B1)
A2A2=WORKDAY.INTL(B1-1,1,"1111011")

VBA Code:
Sub VBA_Find_Next_Friday_Method1()

     Dim dNext_Friday As Date

     dNext_Friday = Next_Friday(Now)

     MsgBox "If today's date is '" & Format(Now, "DD MMM YYYY") & "' then" & vbCrLf & " Next Friday Date is : " & Format(dNext_Friday, "DD MMM YYYY"), vbInformation, "Next Friday Date"

End Sub

Function Next_Friday(MyDate)
     weekdag = Weekday(MyDate, vbFriday)                        'weekday when the week starts on friday
     Next_Friday = MyDate + IIf(weekdag = 1, 0, (8 - weekdag))
End Function

Above macro is working, which is nice, its still putting Friday date of, in this case, 01 Apr 2022 in a Message box, I don't need to see the message if today and..... but i need the date of Friday in CELL A1 in this case it will be 01 Apr 2022 in CELL A1.

Thanks.

1648327589722.png
 
Upvote 0
RedditCFS.xlsx
AB
1vr 01/04/22
2
Blad1
Cell Formulas
RangeFormula
A1A1=next_Friday(TODAY())

That function isn't volatile, so perhaps you must add =today() in a cell somewhere, it doesn't matter where.
 
Upvote 0
I placed today's date in cell A1 and then the formula in cell B1 and nothing happens. The excel version that i have is Excel 2000.

1648415144742.png
 
Upvote 0
My Next Friday.xlsm
ABCDEFGHIJKLMNOPQR
1vr 04/01/202203/28/2022 04:45<---------------- somewhere in your sheet
2vr 04/01/2022
3
Blad1
Cell Formulas
RangeFormula
N1N1=NOW()
A1A1=next_friday(N1)
A2A2=WORKDAY.INTL(TODAY()-1,1,"1111011")
your friday
Was my UDF(macro) in that workbook ?
Now i added "application volatile" and somewhere in your sheet =now().
If that doesn't work, then use the excel function of @Fluff.
VBA Code:
Function Next_Friday(MyDate)
     Application.Volatile
     MyDate = CLng(Date)
     weekdag = Weekday(MyDate, vbFriday)                        'weekday when the week starts on friday
     Next_Friday = MyDate + IIf(weekdag = 1, 0, (8 - weekdag))
End Function
 
Upvote 0

Forum statistics

Threads
1,215,446
Messages
6,124,900
Members
449,194
Latest member
JayEggleton

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