Simulate month

most

Board Regular
Joined
Feb 22, 2011
Messages
107
Office Version
  1. 365
  2. 2019
Platform
  1. Windows
  2. Mobile
I have a problem and need some input from some clever people.
I have some code which does something based on which month it is.

Coloumn 1 - - - - - - - - - - - - - - -Column 2
=MONTH(TODAY())+Z2 - - - - - - -[some code based on the number in column 1, expect number 1-12]

Cell Z2 I use to simulate another month, if it's January and I would like to see February I put in a "1" in Z2. I use a macro to increase or decrease this figure.
Range("Z2") = Range("Z2") - 1
Range("Z2") = Range("Z2") + 1

This works fine for most month of the year, the problem is at turn of the year.
December and I want to see January -> 12+1 = 13 (expect 1)
January and I want to see November -> 1--2 = -1 (expect 11)

Any idea how I can solve this?

regards Marcus
 
Last edited:

Excel Facts

Remove leading & trailing spaces
Save as CSV to remove all leading and trailing spaces. It is faster than using TRIM().
This will always give you the month number of next month:

=MONTH(EDATE(TODAY(),1))
 
Upvote 0
Code:
[/FONT]=MONTH(EDATE(TODAY(),Z2))
Works like a charm, thanks!
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top