+ Reply to Thread
Results 1 to 2 of 2

Selecting sheets to copy/paste values to a new workbook

Hybrid View

  1. #1
    Registered User
    Join Date
    02-15-2013
    Location
    Halesite, New York
    MS-Off Ver
    Excel 2010
    Posts
    39

    Selecting sheets to copy/paste values to a new workbook

    I took a version of a John Walkenbach ready to use macro, and I want to alter it a bit. He created this one that makes a dialog box, and you select pages to print. However, in this case, I want to select pages that I want to make a copy and send to a new sheet. All of the selections would be on one new workbook.

    The following is the code...

    Sub SelectSheets()
        Dim i As Integer
        Dim TopPos As Integer
        Dim SheetCount As Integer
        Dim PrintDlg As DialogSheet
        Dim CurrentSheet As Worksheet
        Dim cb As CheckBox
        Application.ScreenUpdating = False
    
    '   Check for protected workbook
        If ActiveWorkbook.ProtectStructure Then
            MsgBox "Workbook is protected.", vbCritical
            Exit Sub
        End If
    
    '   Add a temporary dialog sheet
        Set CurrentSheet = ActiveSheet
        Set PrintDlg = ActiveWorkbook.DialogSheets.Add
    
        SheetCount = 0
    
    '   Add the checkboxes
        TopPos = 40
        For i = 1 To ActiveWorkbook.Worksheets.Count
            Set CurrentSheet = ActiveWorkbook.Worksheets(i)
    '       Skip empty sheets and hidden sheets
            If Application.CountA(CurrentSheet.Cells) <> 0 And _
                CurrentSheet.Visible Then
                SheetCount = SheetCount + 1
                PrintDlg.CheckBoxes.Add 78, TopPos, 150, 16.5
                    PrintDlg.CheckBoxes(SheetCount).Text = _
                        CurrentSheet.Name
                TopPos = TopPos + 13
            End If
        Next i
    
    '   Move the OK and Cancel buttons
        PrintDlg.Buttons.Left = 240
    
    '   Set dialog height, width, and caption
        With PrintDlg.DialogFrame
            .Height = Application.Max _
                (68, PrintDlg.DialogFrame.Top + TopPos - 34)
            .Width = 230
            .Caption = "Select sheets to move"
        End With
    
    '   Change tab order of OK and Cancel buttons
    '   so the 1st option button will have the focus
        PrintDlg.Buttons("Button 2").BringToFront
        PrintDlg.Buttons("Button 3").BringToFront
    
    '   Display the dialog box
        CurrentSheet.Activate
        Application.ScreenUpdating = True
        If SheetCount <> 0 Then
            If PrintDlg.Show Then
                For Each cb In PrintDlg.CheckBoxes
                    If cb.Value = xlOn Then
                        Worksheets(cb.Caption).Activate
                    End If            Next cb
            End If
        Else
            MsgBox "All worksheets are empty."
        End If
    
    '   Delete temporary dialog sheet (without a warning)
        Application.DisplayAlerts = False
        PrintDlg.Delete
    
    '   Reactivate original sheet
    '    CurrentSheet.Activate
    End Sub
    Where I put the text in bold, is where it activates the sheet that was selected. However as it loops through the list, it will activate and de-activate the sheets, so at the end, only one is selected. I tried a few things, and I am not sure how to get it to hold each selected one, so that all 3 or 4 or whatever sheets are capable of being copied.

    Any ideas?

    Thanks,

    Gary Harding

  2. #2
    Registered User
    Join Date
    02-15-2013
    Location
    Halesite, New York
    MS-Off Ver
    Excel 2010
    Posts
    39

    Re: Selecting sheets to copy/paste values to a new workbook

    any help would be appreciated. Thanks

+ 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. Copy 2 sheets from a open workbook and paste to a closed workbook
    By grimston in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 11-27-2012, 03:27 PM
  2. Copy All Sheets and Paste Values To New Workbook
    By jkelly228 in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 05-02-2011, 06:42 AM
  3. VBA to copy and paste values for all sheets in a workbook
    By LB79 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 08-21-2008, 05:39 AM
  4. Copy and paste range w/o selecting sheets
    By bg18461 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 09-05-2006, 09:01 PM
  5. Selecting data from 1 workbook to copy and paste to a 2nd workbook
    By JackSpam in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 07-19-2005, 10:05 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