+ Reply to Thread
Results 1 to 5 of 5

Macro Button to move 2 tabs to a new workbook

Hybrid View

  1. #1
    Registered User
    Join Date
    01-09-2015
    Location
    Des Moines, IA
    MS-Off Ver
    2010
    Posts
    62

    Macro Button to move 2 tabs to a new workbook

    Hi All,

    I've went through the website and have found numerous threads in regards to this, but none seem to be working specifically for what I'm trying to accomplish.

    I have a workbook with approximately 50 tabs and various macros throughout the workbook. I have two tabs (Billing Sheet & Review Tab) that have references to other tabs that I need to be able to extract and save to desktop as a new name based on cells in the inputs tab --- Basically "Billing + Review Sheet for Inputs!e23"

    I would like a button on both the billing and review tabs that would initiate this macro. I also would like to keep the formatting, while getting rid of the references (basically a copy/paste without formulas). The review tab has a bunch (60) checkboxes that also need to be exported. I would like to keep the macros from the workbook to the new workbook, because I also have a "Print to PDF" macro that I would like to still work.

    What I currently have -- just essentially selects the two sheets and then saves the entire worksheet.

    Sub SaveExcelDesktop()
    
        Dim DeskString As String
        
        Worksheets(Array("Billing", "Review Sheet")).Select
    
        DeskString = CreateObject("WScript.Shell").specialfolders("Desktop")
    
        ActiveSheet.SaveAs Filename:=DeskString & "\" & "Review+Billing of " & Sheets("Inputs").Range("e82").Value & " - " & Sheets("Inputs").Range("e89").Value
    
    End Sub
    Any help would be appreciated.

    Thanks!!
    Travis

  2. #2
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,643

    Re: Macro Button to move 2 tabs to a new workbook

    Try this. It saves a copy of the workbook. Then opens it and deletes the sheets you don't want to keep.

    Sub SaveExcelDesktop()
        
        Dim DeskString As String, ws As Worksheet
        
        Application.ScreenUpdating = False
        Application.DisplayAlerts = False
        
        DeskString = CreateObject("WScript.Shell").SpecialFolders("Desktop") & "\" & _
            "Review+Billing of " & Sheets("Inputs").Range("E82").Value & " - " & Sheets("Inputs").Range("E89").Value & _
            "." & Split(ThisWorkbook.Name, ".")(1)
        
        ThisWorkbook.SaveCopyAs DeskString
        
        With Workbooks.Open(DeskString)
            
            .Sheets("Billing").UsedRange.Value = .Sheets("Billing").UsedRange.Value
            .Sheets("Review Sheet").UsedRange.Value = .Sheets("Review Sheet").UsedRange.Value
        
            For Each ws In .Sheets
                If ws.Name <> "Billing" And ws.Name <> "Review Sheet" Then ws.Delete
            Next ws
            
            .Close SaveChanges:=True
            
        End With
        
        Application.DisplayAlerts = True
        Application.ScreenUpdating = True
        
        MsgBox DeskString, vbInformation, "Billing and Review Copy Saved"
        
    End Sub
    Surround your VBA code with CODE tags e.g.;
    [CODE]your VBA code here[/CODE]
    The # button in the forum editor will apply CODE tags around your selected text.

  3. #3
    Registered User
    Join Date
    01-09-2015
    Location
    Des Moines, IA
    MS-Off Ver
    2010
    Posts
    62

    Re: Macro Button to move 2 tabs to a new workbook

    I'm getting a 400 error. The workbook is created, but tabs don't delete.

  4. #4
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,643

    Re: Macro Button to move 2 tabs to a new workbook

    I think this should work. There may be something additional about your workbook that hasn't been described.

    Do you have an auto-open macro that automatically runs when the file is opened?

    Do you have a userform in the workbook? And if yes, is it displayed or triggered automatically?

    Are the two sheets password protected or hidden?

    Does the code replace the formulas with values on both sheets before it errors?

  5. #5
    Registered User
    Join Date
    01-09-2015
    Location
    Des Moines, IA
    MS-Off Ver
    2010
    Posts
    62

    Re: Macro Button to move 2 tabs to a new workbook

    Almost yes to all of those. I have a userform when the workbook opens for the first time (referenced by a specific cell in the inputs tab). This userform dumps data into the inputs tab.

    Private Sub Workbook_Open()
        With ActiveWorkbook
            If Sheets("Inputs").Range("E5") = "" Then
                UserForm1.Show
            End If
        End With
    End Sub
    The two sheets are also protected (without a password).

    The code does replace the formulas with values on both sheets before it errors.

+ 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. [SOLVED] need coding for macro to move related data from 2 different tabs into a 3rd tab
    By s4driver in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 01-05-2013, 02:09 AM
  2. Macro to loop through and move data to new tabs
    By tso6359 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 03-05-2011, 03:05 PM
  3. Macro to move lines between tabs
    By Chemistification in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 07-08-2010, 08:47 AM
  4. [SOLVED] How do I move the worksheet tabs to the top of the workbook?
    By Deborah Green in forum Excel General
    Replies: 10
    Last Post: 02-16-2006, 11:25 AM
  5. Using a Button Object to move a sheet into a new Workbook
    By MK@Hartford in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 11-22-2005, 11:55 AM
  6. Replies: 2
    Last Post: 11-10-2005, 08:20 PM
  7. [SOLVED] command button move worksheet from one workbook to another
    By Qaspec in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 02-02-2005, 09:06 AM
  8. sort tabs in a workbook other than one at a time with move or cop.
    By Hoflinger in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 01-27-2005, 03:06 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