PC Review


Reply
Thread Tools Rate Thread

Date: End of last month as YYMM

 
 
=?Utf-8?B?Qnl0aHN4LUFkZGFnaW8=?=
Guest
Posts: n/a
 
      24th May 2007
Hello,
I am looking for a good way to capture the YYMM of the last month as a
string.
My macro runs a monthly process and I would like it to automatically save to
monthly directory labeled by the year and month. If I were to run it today,
24-May-2007 I would like the result to be YYMM = "0704".

Could someone suggest a way to do this in VBA without relying on computing
on a worksheet?

Thanks in advance,
 
Reply With Quote
 
 
 
 
Rick Rothstein \(MVP - VB\)
Guest
Posts: n/a
 
      24th May 2007
> I am looking for a good way to capture the YYMM of the last month
> as a string.
> My macro runs a monthly process and I would like it to automatically
> save to monthly directory labeled by the year and month. If I were to
> run it today, 24-May-2007 I would like the result to be YYMM = "0704".


Did you really mean the "last month" as in the one previous May? Assuming
you did...

YourMonth = #24-May-2007#
PreviousMonth = Format$(DateAdd("m",-1,YourDate), "yymm")

Rick

 
Reply With Quote
 
Bob Phillips
Guest
Posts: n/a
 
      24th May 2007
You get that date like so

Format(Date - Day(Date),"YYMM")

to automatically create the directory use

MkDir Format(Date - Day(Date),"YYMM")

but wrap error handling around it in case it already exists

On Error Resume Next
MkDir Format(Date - Day(Date),"YYMM")
On error Goto 0


--
---
HTH

Bob

(there's no email, no snail mail, but somewhere should be gmail in my addy)



"Bythsx-Addagio" <(E-Mail Removed)> wrote in message
news:E7FD860F-8822-4B9E-9066-(E-Mail Removed)...
> Hello,
> I am looking for a good way to capture the YYMM of the last month as a
> string.
> My macro runs a monthly process and I would like it to automatically save
> to
> monthly directory labeled by the year and month. If I were to run it
> today,
> 24-May-2007 I would like the result to be YYMM = "0704".
>
> Could someone suggest a way to do this in VBA without relying on computing
> on a worksheet?
>
> Thanks in advance,



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Generate calendar column month headers in YYMM Format u473 Microsoft Excel Programming 2 25th Dec 2008 11:55 PM
Date formating yymm sconstance Microsoft Excel Misc 2 4th Apr 2008 05:07 PM
Date arithmetic: adding 1 month to prior end of month date =?Utf-8?B?bWFueG1hbg==?= Microsoft Excel Worksheet Functions 2 14th Jul 2006 09:29 PM
Sort month/date/year data using month and date only =?Utf-8?B?U01XODIw?= Microsoft Excel Misc 6 22nd Jun 2006 05:14 PM
Converting Month/Date/Year data & sorting by month/date only =?Utf-8?B?Uy4gV2FzaGluZ3Rvbg==?= Microsoft Excel Worksheet Functions 4 26th Apr 2004 05:01 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 09:17 AM.