+ Reply to Thread
Results 1 to 11 of 11

VBA to identify the current month and previous month based on system date

  1. #1
    Registered User
    Join Date
    05-21-2012
    Location
    india
    MS-Off Ver
    Excel 2010
    Posts
    75

    Post VBA to identify the current month and previous month based on system date

    Hi all,

    I have a 12 sheets belongs to 12 months in a workbook.

    How to identify the current month and previous month sheet in that workbook based on the system date and copy those data in a separate new sheet.

    eg:
    Current Month:July
    Prev Month=June

    Newsheet:

    Month Year
    July 2012
    June 2012

    Please look at the sample attachment.

    Thanks in advance.

    Regards
    Kumar
    Attached Files Attached Files

  2. #2
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,514

    Re: VBA to identify the current month and previous month based on system date

    Something like
    Please Login or Register  to view this content.

  3. #3
    Registered User
    Join Date
    05-21-2012
    Location
    india
    MS-Off Ver
    Excel 2010
    Posts
    75

    Re: VBA to identify the current month and previous month based on system date

    Hi Jindon,

    Thanks for your reply,

    I didn't understand what you are trying to tell,

    I don't have the column like "Date"

    In the workbook sheet names like "Jan '12"....."Jun '12","Jul '12"..etc

    Now from this workbook i just want to find out the current and previous month worksheet only from the available based on the system date and separate out the month and year from those work sheets in a new work sheet using vba code.

    Hope you understand what i am looking for.

    Regards
    Kumar

  4. #4
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,514

    Re: VBA to identify the current month and previous month based on system date

    Please Login or Register  to view this content.

  5. #5
    Registered User
    Join Date
    05-21-2012
    Location
    india
    MS-Off Ver
    Excel 2010
    Posts
    75

    Re: VBA to identify the current month and previous month based on system date

    Hi Jindon,

    Thanks a lot.

    It really helpful to me.
    Regards
    Kumar

  6. #6
    Registered User
    Join Date
    05-21-2012
    Location
    india
    MS-Off Ver
    Excel 2010
    Posts
    75

    Re: VBA to identify the current month and previous month based on system date

    Hi Jindon,

    In the workbook sheet names are like this "Jan '12","Feb '12","Mar '12","April '12","May '12","June '12","Jul '12","Aug '12","Sept '12","Oct '12","Nov '12",
    "Dec '12"

    see these are not in the same format.

    Now how to find the current month and previous month sheets from this kind of workbook.

    Please provide a solution to me.

    Regards
    Kumar

  7. #7
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,514

    Re: VBA to identify the current month and previous month based on system date

    Why do you make it so complex?

    You will get trouble specifying sheet name if you have no rule to name the sheet and if you can not do it for yourself, you should maintain the rule.

    Here's a simple sample (no error trap)
    Please Login or Register  to view this content.

  8. #8
    Registered User
    Join Date
    05-21-2012
    Location
    india
    MS-Off Ver
    Excel 2010
    Posts
    75

    Re: VBA to identify the current month and previous month based on system date

    Jindon,

    Thanks a lot. This is what i want
    You are excellent.

    Regards
    Kumar

  9. #9
    Registered User
    Join Date
    05-21-2012
    Location
    india
    MS-Off Ver
    Excel 2010
    Posts
    75

    Re: VBA to identify the current month and previous month based on system date

    Jindon,

    If the current month is "Jan-2012" in my system calender.
    Now if i run the code,I will get
    Current Month : Jan-2012(I have the sheet Jan '12)
    Previous Month : Dec-2012 (But we need to get like Dec-2011)(and i don't have that sheet(Dec '11) in my workbook)
    If my workbook doesn't have Dec '11 sheet.Then the previous month should not load.

    How can i resolve this problem?

    Regards
    Kumar

    ---------- Post added at 05:04 PM ---------- Previous post was at 04:54 PM ----------

    Jindon,

    This is what i am using the code for that
    Please Login or Register  to view this content.
    I think now i clear the problem.

    Regards
    Kumar
    Last edited by Cutter; 07-26-2012 at 09:12 AM. Reason: Removed duplication

  10. #10
    Forum Expert Cutter's Avatar
    Join Date
    05-24-2004
    Location
    Ontario,Canada
    MS-Off Ver
    Excel 2010
    Posts
    6,451

    Re: VBA to identify the current month and previous month based on system date

    @ ravikumar00008

    Based on your last post it seems that you are satisfied with the solution(s) you've received but you haven't marked your thread as SOLVED. I'll do that for you now but please keep in mind for your future threads that Rule #9 requires you to do that yourself. If your problem has not been solved you can use Thread Tools (located above your first post) and choose "Mark this thread as unsolved".
    Thanks.

  11. #11
    Registered User
    Join Date
    05-21-2012
    Location
    india
    MS-Off Ver
    Excel 2010
    Posts
    75

    Re: VBA to identify the current month and previous month based on system date

    Hi,

    I am trying to mark it as solved.But i don't know how to mark it.

    Can you please tell me how to do it?

    Regards
    Kumar

    ---------- Post added at 07:34 PM ---------- Previous post was at 07:00 PM ----------

    Jindon,

    one last thing i want in this discussion.

    Right now we are able to identify the current month and previous month sheets.It is fine.
    I want another way also,Like
    I need to find all the previous months sheets from the current month along with the current month.

    ex:
    CurrMonth=July
    PrevMonths=June,May,April,March,Feb,Jan.

    Regards
    Kumar

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1