Last day of week problem

DaveUK

Board Regular
Joined
Jan 24, 2005
Messages
245
Please can someone suggest the VBA code to do the following.

The last day of the week is Sunday.
The format i want for the date is : dd/mm/yyyy

I want to store the data of the last day of the week in a variable LastDayOfWeek. (pre Dimmed as Dim LastDayOfWeek as Date)

I want then to check for the value of LastDayOfWeek in row3 starting at column B and then across to the right. If the value is found i then want to exit the sub otherwise i want the value LastDayOfWeek pasted into the next Empty Cell in Row 3.

TIA
 

Excel Facts

Does the VLOOKUP table have to be sorted?
No! when you are using an exact match, the VLOOKUP table can be in any order. Best-selling items at the top is actually the best.
If I understood you correctly, then this should work:

Sub LaLa()
Dim LastDayOfWeek As Date, r As Long, c As Integer

LastDayOfWeek = Int(Now())
Do Until Weekday(LastDayOfWeek) = vbSunday
LastDayOfWeek = LastDayOfWeek + 1
Loop
r = 3
c = 2

Do While Cells(r, c).Value <> ""
If Cells(r, c).Value = LastDayOfWeek Then Exit Sub
c = c + 1
Loop
Cells(r, c) = LastDayOfWeek

End Sub
 
Upvote 0
Resurrecting an old topic but how do i alter the code to give me last weeks end of the week day.

For example today is 15th March if i wanted to find out last Sundays date.

I will be running the macro on a weekday and need the end of week date of last Sunday.(The week just gone).

TIA
 
Upvote 0
Just change

LastDayOfWeek = LastDayOfWeek + 1

to

LastDayOfWeek = LastDayOfWeek - 1

You'll then be going backwards 1 day at a time until the weekday is Sunday
 
Upvote 0

Forum statistics

Threads
1,214,591
Messages
6,120,429
Members
448,961
Latest member
nzskater

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