+ Reply to Thread
Results 1 to 4 of 4

Copy worksheet and timestamp

  1. #1
    Registered User
    Join Date
    11-12-2008
    Location
    Iowa
    Posts
    32

    Copy worksheet and timestamp

    How do I copy the existing content of a worksheet into a new tab and name it with a date and time stamp? The worksheet has a form in it. Is it possible to copy the template of the form without copying the values?

    E.g.

    Name: John Doe
    Age: 29.

    When you run the macro, it saves that page and values and then opens up a new tab called 2:15PM-12/29/10 and in that it will have:

    Name:
    Age:

    Please advise.

    Thank you.

  2. #2
    Forum Expert
    Join Date
    11-29-2010
    Location
    Ukraine
    MS-Off Ver
    Excel 2019
    Posts
    4,168

    Re: Copy worksheet and timestamp

    Yes, it is possible.
    The most efficient way is to create a ready sheet template and insert a new templated sheet when necessary with layout set without any data.
    Another way is to copy sheet with data and delete everything unnecessary.

  3. #3
    Registered User
    Join Date
    11-12-2008
    Location
    Iowa
    Posts
    32

    Re: Copy worksheet and timestamp

    I figured out most of it. I made a copy of the worksheet and just cleared out the contents from the cells that I wanted cleared. However, the renaming part is not working. The new tab should be named with a time stamp, however, it doesn't do that. Could somebody look at my code and tell me what I am doing wrong?

    Thank you.

    Sub CopyDMCO()

    ActiveSheet.Copy after:=Sheets(Sheets.Count)
    Dim sname As String
    sname = Format(DateTime.Now, "mm-dd-yyyy hh-MM-ss")
    Worksheets(Sheets.Count).Name = sname
    ActiveSheet.Range("B11").ClearContents
    ActiveSheet.Range("B13:B15").ClearContents
    ActiveSheet.Range("B18:B23").ClearContents
    ActiveSheet.Range("E7:G7").ClearContents
    ActiveSheet.Range("E9:G9").ClearContents
    ActiveSheet.Range("D12:G24").ClearContents



    End Sub

  4. #4
    Forum Contributor TechRetard's Avatar
    Join Date
    06-14-2009
    Location
    Houston, TX
    MS-Off Ver
    Excel 2010
    Posts
    202

    Re: Copy worksheet and timestamp

    Quote Originally Posted by athard View Post
    The new tab should be named with a time stamp, however, it doesn't do that. Could somebody look at my code and tell me what I am doing wrong?

    End Sub
    It is working for me, what errors are you getting? Can you attached your sheet possibly for clarification. Are you saying the second part with the dash isn't a time stamp? You can't use " : " when naming a tab so you would have to use dashes...

    you could possibly use "mm-dd-yyyy HH.MM.SS AM/PM" to make it more clear?
    Last edited by TechRetard; 12-30-2010 at 01:34 PM.

+ 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