Dynamic Year

Dummy Excel

Well-known Member
Joined
Sep 21, 2005
Messages
1,004
Office Version
  1. 2019
  2. 2010
  3. 2007
Platform
  1. Windows
Hi All,
I'm going crazy trying to get this logic right...

I have a report that needs to be done monthly. The macro finds the previous month, opens it and copies the data into my new report for history. The problem im having is come Jan 11, its looking for the previous report as Dec 11.

Scenario for the predefined Values are:
Code:
YY	11
PreYY	10
CurMnth	Jan
PriorMnth	Nov
PreMnth	Dec
Customer	ABC
Business	XYZ

Rich (BB code):
    If YY = "11" And CurMnth = "Jan" And PreMnth = "Dec" Then
        Windows(Customer & " " & Business & " OF " & PriorMnth & " " & PreYY & ".xls").Activate
    Else
        Windows(Customer & " " & Business & " OF " & PriorMnth & " " & YY & ".xls").Activate
    End If

So my question is how can I make the "11" (in bold) dynamic so come 2012, I don't need to make any changes?

thanks in advance
Samuel
 

Excel Facts

Create a Pivot Table on a Map
If your data has zip codes, postal codes, or city names, select the data and use Insert, 3D Map. (Found to right of chart icons).
hey Dan, tried your code before and it didnt work, although I tried again and it works...thanks again for your help
 
Upvote 0
No probs mate, always happy to help :).

To explain the code it takes the date of today and replaces the day with 01, it then takes away 1 from the result giving us always the last day of last month :).
 
Upvote 0

Forum statistics

Threads
1,225,156
Messages
6,183,233
Members
453,152
Latest member
ChrisMd

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