+ Reply to Thread
Results 1 to 8 of 8

Create a new Worksheet which name is yesterday's date

  1. #1
    Registered User
    Join Date
    08-08-2012
    Location
    London
    MS-Off Ver
    Excel 2003
    Posts
    8

    Create a new Worksheet which name is yesterday's date

    Hi Guys,

    I'm currently trying to write a vba macro that would create a new worksheet in an existing excel file. This new worksheet must be named: Deals [date of yesterday] apart from mondays, where the worksheet must be named Deals date of 3 days ago (the friday before the monday);

    Here's what I've came up with:

    Please Login or Register  to view this content.

    But of course, it isn't working

    I haven't had any classes on vba so the above must be full of mistakes. Please feel free to correct them, I would really appreciate it.

    Thanks a lot

    CHeers
    Last edited by Cutter; 08-08-2012 at 06:26 PM. Reason: Added code tags

  2. #2
    Forum Expert
    Join Date
    07-16-2010
    Location
    Northumberland, UK
    MS-Off Ver
    Excel 2007 (home), Excel 2010 (work)
    Posts
    3,054

    Re: Create a new Worksheet which name is yesterday's date

    Try this:

    Please Login or Register  to view this content.

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

    Re: Create a new Worksheet which name is yesterday's date

    @ Hugopellegrini

    Welcome to the forum.

    Please notice that code tags have been added to your post(s). The forum rules require them so please keep that in mind and add them yourself whenever showing code in any of your future posts. To see instructions for applying them, click on the Forum Rules button at top of the page and read Rule #3.
    Thanks.

  4. #4
    Registered User
    Join Date
    08-08-2012
    Location
    London
    MS-Off Ver
    Excel 2003
    Posts
    8

    Re: Create a new Worksheet which name is yesterday's date

    It's working fine, thank you guys!
    I just want to know if it is impossible to set the date format as dd/mm/yyyy rather than ddmmyy
    Also, the sheet that is added doesn't come just after the 5th one but at the end. Do you know a quick fix to that?

    Thanks a lot!

  5. #5
    Registered User
    Join Date
    08-08-2012
    Location
    london,england
    MS-Off Ver
    Excel 2003
    Posts
    10

    Re: Create a new Worksheet which name is yesterday's date

    yes if it comes as dd/MMM/YYYY that would be great.

  6. #6
    Forum Expert
    Join Date
    07-16-2010
    Location
    Northumberland, UK
    MS-Off Ver
    Excel 2007 (home), Excel 2010 (work)
    Posts
    3,054

    Re: Create a new Worksheet which name is yesterday's date

    You can't have the date as dd/mm/yy as slashes aren't permitted in sheet names, but it could be set to dd-mm-yy. I've also changed the code to add the new sheet after the 5th sheet:

    Please Login or Register  to view this content.

  7. #7
    Registered User
    Join Date
    08-08-2012
    Location
    London
    MS-Off Ver
    Excel 2003
    Posts
    8

    Re: Create a new Worksheet which name is yesterday's date

    Thank you so much Andrew, that works perfectly!

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

    Re: Create a new Worksheet which name is yesterday's date

    @ Hugopellegrini

    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.

    Also, as a new member of the forum, you may not be aware that you can thank those who have helped you by clicking the small star icon located in the lower left corner of the post in which the help was given. By doing so you can add to the reputation(s) of those who helped.

+ 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