Solved

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

Posted on 2013-01-10
2
4,482 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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

This code takes an Excel list of URL’s and adds a header titled “URL List”. It then searches through all URL’s in column “A”, looking for duplicates. When a duplicate is found, it is moved to the top of the list. The duplicate URL’s are then highlig…
Do you use a spreadsheet like Microsoft's Excel?  Have you ever wanted to link out to a non excel file on your computer or network drive?  This is the way I found to do it!
The viewer will learn how to use the =DISCRINV command to create a discrete random variable, use this command to model a set of probabilities and outcomes in a Monte Carlo simulation, and learn how to find the standard deviation of a set of probabil…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

630 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