Date Calculation and variable setting

Nelboy

Board Regular
Joined
Mar 28, 2014
Messages
53
Office Version
  1. 365
Platform
  1. Windows
Good Morning

I am hoping someone can help as I am a little stuck

I am trying to calculate a date range of when UTC is applicable. Essentially in the UK this is from the Last Sunday in March through to the Last Sunday in October every year.

I have worked out that the following formula in excel
Excel Formula:
FLOOR(EOMONTH(I3,0)-1,7)+1
give me the last Sunday in March if Cell I3 is say 1/3/2020

is their a simple way of converting
Excel Formula:
FLOOR(EOMONTH(I3,0)-1,7)+1
to VBA to say strStartDate = "FLOOR(EOMONTH(" & format("1/3/2020","dd-mm-yy") & ",0)-1,7)+1" , strEndDate = "FLOOR(EOMONTH(" & format("1/10/2020","dd-mm-yy") & ",0)-1,7)+1"

I hope this makes since as to what I am trying to do and someone can help

regards
 

Excel Facts

What is the fastest way to copy a formula?
If A2:A50000 contain data. Enter a formula in B2. Select B2. Double-click the Fill Handle and Excel will shoot the formula down to B50000.
VBA Code:
  strStartDate = Format(Evaluate("FLOOR(EOMONTH(DATE(YEAR(Today()),3,1),0)-1,7)+1"), "dd/mm/yyyy")
  strEndDate = Format(Evaluate("FLOOR(EOMONTH(DATE(YEAR(Today()),10,1),0)-1,7)+1"), "dd/mm/yyyy")

Alternatively...
VBA Code:
  strStartDate = Format(Int((DateSerial(Year(Date), 3 + 1, 0) - 1) / 7) * 7 + 1, "dd/mm/yyyy")
  strEndDate = Format(Int((DateSerial(Year(Date), 10 + 1, 0) - 1) / 7) * 7 + 1, "dd/mm/yyyy")
 
Last edited:
Upvote 0
Solution
VBA Code:
  strStartDate = Format(Evaluate("FLOOR(EOMONTH(DATE(YEAR(Today()),3,1),0)-1,7)+1"), "dd/mm/yyyy")
  strEndDate = Format(Evaluate("FLOOR(EOMONTH(DATE(YEAR(Today()),10,1),0)-1,7)+1"), "dd/mm/yyyy")

Alternatively...
VBA Code:
  strStartDate = Format(Int((DateSerial(Year(Date), 3 + 1, 0) - 1) / 7) * 7 + 1, "dd/mm/yyyy")
  strEndDate = Format(Int((DateSerial(Year(Date), 10 + 1, 0) - 1) / 7) * 7 + 1, "dd/mm/yyyy")
Thanks very much
 
Upvote 0

Forum statistics

Threads
1,214,573
Messages
6,120,310
Members
448,955
Latest member
Dreamz high

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