Solved

Excel VBA:  Date range formula

Posted on 2014-10-15
5
318 Views
Last Modified: 2014-10-15
Hello Experts,

Is there a formula in excel that would provide a weekly range for the previous week (Monday to Sunday).  So example if I was to use the formula now, it will show
10-06-14 to 10-12-14


it should look the same as the above format.

Much appreciated it!
0
Comment
Question by:Maliki Hassani
5 Comments
 
LVL 12

Assisted Solution

by:jkaios
jkaios earned 167 total points
ID: 40383018
To calculate last week:

Dim dtBeg as date, dtEnd as date

dtBeg = DateAdd("ww", -1, Date - Weekday(Date) + 1)
dtEnd = DateAdd("ww", -1, Date - Weekday(Date) + 7)

msgbox dtBeg & " - " & dtEnd

Open in new window

0
 
LVL 12

Expert Comment

by:jkaios
ID: 40383025
After you've calculated last week's date range, you can then format it to the way you want:

msgbox "beg date: " & format(dtBeg, "MM-dd-yy") & vbcrLf
               "end date: " & format(dtEnd, "MM-dd-yy")
0
 
LVL 76

Assisted Solution

by:GrahamSkan
GrahamSkan earned 166 total points
ID: 40383057
@Maliki Hassani,
You ask for a formula but you have added VBA Basic programming as a topic. Be aware that VBA and formulae are different things. Formulae will normally give automatic updates in the sheet. VBA macros need to be run specifically and could take considerably more time to process,
0
 

Author Comment

by:Maliki Hassani
ID: 40383078
Great point. I will use a formula rather than a macro.
0
 
LVL 22

Accepted Solution

by:
Ejgil Hedegaard earned 167 total points
ID: 40383091
A formula could be like this

=TEXT(TODAY()-WEEKDAY(TODAY(),2)-6,"mm-dd-yy")&" to "&TEXT(TODAY()-WEEKDAY(TODAY(),2),"mm-dd-yy")

Open in new window

0

Featured Post

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
Excel can be a tricky bit of software to get your head around. Whilst you’ll be able to eventually get to grips with the basic understanding of how to get by, there are a few Excel tips that not everybody will even know about let alone know how to d…
This Micro Tutorial demonstrates how to create Excel charts: column, area, line, bar, and scatter charts. Formatting tips are provided as well.
This Micro Tutorial will demonstrate in Microsoft Excel how to add style and sexy appeal to horizontal bar charts.

730 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question