Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2016-09-05
4
Medium Priority
?
34 Views
Last Modified: 2016-09-05
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.

Thanks in advance,

swjtx99
DateExample.xlsx
0
Comment
Question by:swjtx99
[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
  • 3
4 Comments
 
LVL 32

Accepted Solution

by:
Subodh Tiwari (Neeraj) earned 2000 total points
ID: 41785134
Please try something like this.....

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

Open in new window

DateExample.xlsm
0
 
LVL 32

Expert Comment

by:Subodh Tiwari (Neeraj)
ID: 41785137
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

Open in new window

0
 

Author Closing Comment

by:swjtx99
ID: 41785181
Worked Great!

Thanks again Subodh!

swjtx99
0
 
LVL 32

Expert Comment

by:Subodh Tiwari (Neeraj)
ID: 41785496
You're welcome. Glad to help.
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

How to get Spreadsheet Compare 2016 working with the 64 bit version of Office 2016
This article describes a serious pitfall that can happen when deleting shapes using VBA.
The viewer will learn how to use a discrete random variable to simulate the return on an investment over a period of years, create a Monte Carlo simulation using the discrete random variable, and create a graph to represent the possible returns over…
This Micro Tutorial will demonstrate in Microsoft Excel how to add style and sexy appeal to horizontal bar charts.

688 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