+ Reply to Thread
Results 1 to 4 of 4

Button to save existing sheet as a new sheet

  1. #1
    Registered User
    Join Date
    10-02-2023
    Location
    Flagstaff
    MS-Off Ver
    365
    Posts
    4

    Button to save existing sheet as a new sheet

    Is there a way to code a button to take a range of cells from the sheet the button is on and create a new sheet with all that data copied onto the new sheet vs referenced.
    It would have a cell to insert a name for the new sheet and the button below it. The main goal is to have my sales data on one sheet and when I hit the button it would
    create a separate sheet under that days date(as name) and reset the sheet to all zeros for the next days data. I havent had much experience with VBA since college so
    please forgive me.

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

    Re: Button to save existing sheet as a new sheet

    try to attach a sample file.
    Quang PT

  3. #3
    Registered User
    Join Date
    10-02-2023
    Location
    Flagstaff
    MS-Off Ver
    365
    Posts
    4

    Re: Button to save existing sheet as a new sheet

    So this code is working to make a copy of my active sheet and place it at the end of my list of sheets.
    I cant figure out how to make it take a range of cells from the active sheet vs the whole sheet.
    This is not my original code but something I have butchered to suite my purposes.


    Sub Button3_Click()
    ActiveSheet.Copy after:=Sheets(Sheets.Count)
    Sheets(Sheets.Count).Name = GetName
    End Sub

    Private Function GetName() As String
    Dim x As Long, n As String
    n = ActiveSheet.Range("A1")
    If SheetExists(n) Then
    Do
    x = x + 1
    If Not SheetExists(n & x) Then Exit Do
    Loop
    n = n & x
    End If
    GetName = n
    End Function

    Private Function SheetExists(aName As String) As Boolean
    On Error Resume Next
    Dim sh As Worksheet: Set sh = Sheets(aName)
    If Err = 0 Then SheetExists = True Else SheetExists = False
    End Function

  4. #4
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Arrow Re: Button to save existing sheet as a new sheet


    • Set first a Range variable on what you called « range of cells from the active sheet » …

    • Create the new worksheet.

    • Apply the copy method to the Range variable with its destination parameter filled like cell A1.

    • Set the Range variable to Nothing …

+ 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: 1
    Last Post: 03-01-2022, 03:25 AM
  2. command button to Save As sheet in new workook and Close options to hide sheet
    By AmandaM73 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 11-02-2018, 03:59 AM
  3. Replies: 2
    Last Post: 03-01-2017, 04:12 PM
  4. Replies: 1
    Last Post: 10-09-2015, 02:56 PM
  5. Save multiple sheet/print sheet with one command button
    By GJR in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 04-23-2014, 03:06 PM
  6. Copy the data in existing sheet to a different workbook by using a button
    By Fixxxer1234 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 09-11-2013, 02:25 AM
  7. Macro to save each sheet with existing name and to the location specified
    By vivek_work in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 04-12-2013, 08:21 AM

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