+ Reply to Thread
Results 1 to 8 of 8

Copy sheet within a workbook and automatically rename it based on dates, for the month

  1. #1
    Registered User
    Join Date
    10-08-2020
    Location
    London
    MS-Off Ver
    office 365
    Posts
    5

    Question Copy sheet within a workbook and automatically rename it based on dates, for the month

    i found this VBA code from another thread...


    Sub DuplicateTemplateSheet()
    Dim i As Integer, m As Integer, y As Integer

    Dim ws As Worksheet: Set ws = Sheets("MASTER COPY")
    m = Month(ws.Range("E3"))
    y = Year(ws.Range("E3"))


    For i = 1 To Day(Application.EoMonth(ws.Range("E3"), 0))
    Sheets("MASTER COPY").Copy After:=Sheets(Sheets.Count)
    With Sheets(Sheets.Count)
    .Name = Format(i, "00") & "-" & Format(m, "00") & "-" & y
    .Range("E3") = DateSerial(y, m, i)
    End With
    Next i
    End Sub


    Question is how to change the format so the date in the new tabs are dd mmm (01 Apr) for example...

    the code i found is perfect for my needs, just the date format in the New Tabs created!

  2. #2
    Forum Expert bebo021999's Avatar
    Join Date
    07-22-2011
    Location
    Vietnam
    MS-Off Ver
    Excel 2016
    Posts
    9,466

    Re: Copy sheet within a workbook and automatically rename it based on dates, for the month

    may be:
    PHP Code: 
    Sub DuplicateTemplateSheet()
    Dim i As IntegerAs IntegerAs Integer
    Dim ws 
    As WorksheetSet ws Sheets("MASTER COPY")
    Month(ws.Range("E3"))
    Year(ws.Range("E3"))
    For 
    1 To Day(Application.EoMonth(ws.Range("E3"), 0))
        
    Sheets("MASTER COPY").Copy After:=Sheets(Sheets.Count)
        
    With Sheets(Sheets.Count)
            .
    Range("E3") = Format(DateSerial(ymi), "dd mmm")
            .
    Name Format(i"00") & "-" Format(m"00") & "-" y
        End With
    Next i
    End Sub 
    Quang PT

  3. #3
    Registered User
    Join Date
    10-08-2020
    Location
    London
    MS-Off Ver
    office 365
    Posts
    5

    Re: Copy sheet within a workbook and automatically rename it based on dates, for the month

    Thank You,
    Sadly the date is still showing full, 01-04-2023, Rather than 01 Apr as i don't need the year..

    i appreciate your help and time you have taken

  4. #4
    Forum Expert bebo021999's Avatar
    Join Date
    07-22-2011
    Location
    Vietnam
    MS-Off Ver
    Excel 2016
    Posts
    9,466

    Re: Copy sheet within a workbook and automatically rename it based on dates, for the month

    There are two date: in tab name and in cell E3.
    In my code, 1st Apr 2003 displayed :
    - In tab name: 01-04-2023
    - In cell E3: :01 Apr
    Is it are you looking for?
    If not, what is it?

  5. #5
    Registered User
    Join Date
    10-08-2020
    Location
    London
    MS-Off Ver
    office 365
    Posts
    5

    Re: Copy sheet within a workbook and automatically rename it based on dates, for the month

    Quote Originally Posted by bebo021999 View Post
    There are two date: in tab name and in cell E3.
    In my code, 1st Apr 2003 displayed :
    - In tab name: 01-04-2023
    - In cell E3: :01 Apr
    Is it are you looking for?
    If not, what is it?
    That's what i was looking for, The tab name is shorter version of the cell date

    The Cell date is the full Date, and the Tab is the shorter version with no year, (01 Apr)

    i love learning and this one has stumped me...
    Last edited by albegood4u; 04-28-2023 at 05:55 AM.

  6. #6
    Registered User
    Join Date
    10-08-2020
    Location
    London
    MS-Off Ver
    office 365
    Posts
    5

    Re: Copy sheet within a workbook and automatically rename it based on dates, for the month

    i was playing around and after many errors i managed the following...
    (i know it will look simple to some what i done, but with No VBA or Macro experience)

    Sub DuplicateTemplateSheet()
    Dim i As Integer, m As Integer, y As Integer

    Dim ws As Worksheet: Set ws = Sheets("MASTER COPY")
    d = Day(ws.Range("E3"))
    m = Month(ws.Range("E3"))
    y = Year(ws.Range("E3"))


    For i = 1 To Day(Application.EoMonth(ws.Range("E3"), 0))
    Sheets("MASTER COPY").Copy after:=Sheets(Sheets.Count)
    With Sheets(Sheets.Count)
    .Range("E3") = Format(DateSerial(y, m, i), "dd mmm")
    .Name = Format(i, "00") & " " & Format(m, "00")

    End With
    Next i
    End Sub

    Its almost near Perfect, Just cant seem to change the Name in the Tabs to the correct format!
    Based on May 2023,
    Tabs now renamed as (01 05) and so on
    But i would like them to be 01 May and so on..

    i know i am missing something so simple!

  7. #7
    Forum Expert bebo021999's Avatar
    Join Date
    07-22-2011
    Location
    Vietnam
    MS-Off Ver
    Excel 2016
    Posts
    9,466

    Re: Copy sheet within a workbook and automatically rename it based on dates, for the month

    Wiy my code in #2, try
    PHP Code: 
    .Name Format(.Range("E3"),"dd mmm"

  8. #8
    Registered User
    Join Date
    07-20-2023
    Location
    India
    MS-Off Ver
    2021
    Posts
    1

    Re: Copy sheet within a workbook and automatically rename it based on dates, for the month

    A little modification does the game

    Sub DuplicateTemplateSheet()
    Dim i As Integer, m As Integer, y As Integer

    Dim ws As Worksheet: Set ws = Sheets("MASTER COPY")
    d = Day(ws.Range("E3"))
    m = Month(ws.Range("E3"))
    y = Year(ws.Range("E3"))


    For i = 1 To Day(Application.EoMonth(ws.Range("E3"), 0))
    Sheets("MASTER COPY").Copy after:=Sheets(Sheets.Count)
    With Sheets(Sheets.Count)
    .Range("E3") = Format(DateSerial(y, m, i), "dd-mm-yyyy")
    .Name = Format(i, "00") & "-" & Format(m, "00") & "-" & Format(y, "0000")

    End With
    Next i
    End Sub

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Replies: 5
    Last Post: 04-24-2023, 04:28 PM
  2. Macro to copy a sheet for each weekday of the month and rename it as such.
    By taylorsm in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 11-02-2016, 02:32 PM
  3. [SOLVED] Macro to copy sheet and rename tab to dates
    By Ozman89 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 03-09-2016, 12:44 PM
  4. [SOLVED] Copy sheet, rename with name and month increment
    By julhs in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 02-20-2016, 12:13 PM
  5. [SOLVED] Copy a sheet, rename it by value in range then export product to new workbook and rename
    By MagicMan in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 03-31-2015, 07:24 PM
  6. Macro to copy sheet, then rename month name, then filter the results by that name
    By jateelover in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 07-01-2014, 05:31 PM
  7. Copy and rename a sheet in an existing workbook?
    By robertse in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 06-09-2010, 02:00 PM

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