Solved

vba code to get first date and last day of previous month

Posted on 2013-01-10
2
4,238 Views
Last Modified: 2013-01-10
For example, it's January now, I want to get first date of December  as "12/01/2012", last date is "12/31/2012"

Thanks.
0
Comment
Question by:HemlockPrinters
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 81

Accepted Solution

by:
zorvek (Kevin Jones) earned 400 total points
ID: 38764971
First day of previous month:

    Debug.Print DateSerial(Year(Now()), Month(Now) - 1, 1)

Last day of previous month:

    Debug.Print DateSerial(Year(Now()), Month(Now), 0)

Kevin
0
 
LVL 27

Assisted Solution

by:MacroShadow
MacroShadow earned 100 total points
ID: 38764991
Here you will find many useful date functions, for example:

    Business days between two dates.
    Business day + days = next business date
    Easter (Western)
    Age
    First Day of Quarter
    First Day of Week
    First Day of Month
    First Day of Previous Month
    First Day of Next Month
    Last Day of Quarter
    Last Day of Week
    Last Day of Month
    Last Day of Previous Month
    Last Day of Next Month
    First Weekday (sun, mon, etc) following specified date.
    Special DateDiff function that separates the answer into parts
0

Featured Post

Enroll in May's Course of the Month

May’s Course of the Month is now available! Experts Exchange’s Premium Members and Team Accounts have access to a complimentary course each month as part of their membership—an extra way to increase training and boost professional development.

Question has a verified solution.

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

Introduction This Article briefly covers methods of calculating the NPV and IRR variants in Excel as well as the limitations in calculating and interpreting IRR results. Paraphrasing Richard Shockley, author of my favourite finance reference tex…
In Part II of this series, I will discuss how to identify all open instances of Excel and enumerate the workbooks, spreadsheets, and named ranges within each of those instances.
Graphs within dashboards are meant to be dynamic, representing data from a period of time that will change each time the dashboard is updated with new data. Rather than update each graph to point to a different set within a static set of data, t…
This Micro Tutorial demonstrate the bugs in Microsoft Excel for Mac with Pivot Charts.

738 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