Solved

# Change dates in 2 Cells (first and last day of month)

Posted on 2016-09-05
25 Views
Hi,

I have a sheet where I am constantly changing dates (first and last day of a month). Looking for a way to do this with one click.

Attached is an example of what I am looking for. Whatever month is in the cells, just hit increment or decrement to get the first and last dates for the next (or previous) month.

swjtx99
DateExample.xlsx
0
Question by:swjtx99
• 3

LVL 28

Accepted Solution

Subodh Tiwari (Neeraj) earned 500 total points

``````Sub IncrementMonth()
Range("F1").Value = WorksheetFunction.EDate(Range("F1").Value, 1)
Range("F2").Value = WorksheetFunction.EoMonth(Range("F2").Value, 1)
End Sub

Sub DecrementMonth()
Range("F1").Value = WorksheetFunction.EoMonth(Range("F1").Value, -2) + 1
Range("F2").Value = WorksheetFunction.EoMonth(Range("F2").Value, -1)
End Sub
``````
DateExample.xlsm
0

LVL 28

Expert Comment

For IncrementMonth, you can also use the following code....

``````Sub IncrementMonth()
Range("F1").Value = WorksheetFunction.EoMonth(Range("F1").Value, 0) + 1
Range("F2").Value = WorksheetFunction.EoMonth(Range("F2").Value, 1)
End Sub
``````
0

Author Closing Comment

Worked Great!

Thanks again Subodh!

swjtx99
0

LVL 28

Expert Comment

0

## Featured Post

Dealing with unintended Excel Active-X resizing quirks (VBA code simulates "self correction") David Miller (dlmille) Intro Not everyone is a fan of Active-X controls in spreadsheets (as opposed to the UserForm approach, the older Form controls …
This tutorial explains how to create a series of drop-down lists that are dependent upon prior selections to guide (“force”) the user to make the correct selection and reduce data errors within Microsoft Excel. Excel 2010 was used for this tutorial;…
Viewers will learn the basics of slicers and timelines for both PivotTables and standard Excel tables in Excel 2013.
The viewer will learn how to simulate a series of coin tosses with the rand() function and learn how to make these “tosses” depend on a predetermined probability. Flipping Coins in Excel: Enter =RAND() into cell A2: Recalculate the random variable…