+ Reply to Thread
Results 1 to 4 of 4

Thread: Select & copy spreadsheets to new folder

  1. #1
    Forum Contributor
    Join Date
    06-24-2009
    Location
    SCOTLAND
    MS-Off Ver
    Excel 2007
    Posts
    109

    Select & copy spreadsheets to new folder

    My knowledge of coding / VBA is very limited. I struggle to find the correct coding to do the task but I can follow the code and enjoy doing so, with help from members of forums like this. Any help in achieving the following would be very much appreciated.
    I've attached a worksheet to aid my description.
    I want to select any one or all of the buttons marked A,B,C & D. In this instance I've selected B & D. The A,B,C & D buttons represent the 4 spreadsheets listed in the tabs at the bottom. Note I've used Form Control buttons for this purpose.
    After selecting B & D (or any other selected) I then want to copy spreadsheets B & D and place them in another folder / workbook when 'Button 6' is clicked.
    Attached Files Attached Files

  2. #2
    Valued Forum Contributor tigeravatar's Avatar
    Join Date
    03-25-2011
    Location
    USA
    MS-Off Ver
    Excel 2003 - 2007
    Posts
    2,352

    Re: Select & copy spreadsheets to new folder

    heliskier89,

    Attached is a modified version of your workbook. The button has the following macro bound to it:
    Sub btn_click()
        
        Dim strDestName As String:  strDestName = "SaveTest.xlsx"
        Dim strDestPath As String:  strDestPath = Environ("UserProfile") & "\Desktop\"
        
        Application.ScreenUpdating = False
        
        Dim wbSource As Workbook:   Set wbSource = ActiveWorkbook
        Dim wsActive As Worksheet:  Set wsActive = wbSource.ActiveSheet
        Dim wbDest As Workbook:     Set wbDest = Workbooks.Add
        wbDest.SaveAs Filename:=strDestPath & strDestName
        
        Dim chk As CheckBox, CopyCount As Long
        For Each chk In wsActive.CheckBoxes
            If chk.Value = 1 Then
                Dim ws As Worksheet
                For Each ws In wbSource.Worksheets
                    If Trim(ws.Name) = Trim(chk.Caption) Then
                        ws.Copy After:=Workbooks(wbDest.Name).Sheets(Sheets.Count)
                        CopyCount = CopyCount + 1
                        If CopyCount = 1 Then
                            Dim ws1 As Worksheet
                            Application.DisplayAlerts = False
                            For Each ws1 In wbDest.Worksheets
                                If Trim(ws1.Name) <> Trim(chk.Caption) Then
                                    ws1.Delete
                                End If
                            Next ws1
                            Application.DisplayAlerts = True
                        End If
                    Exit For
                    End If
                Next ws
            End If
        Next chk
        
        wbDest.Close True
        If CopyCount = 0 Then Kill strDestPath & strDestName
        
        Application.ScreenUpdating = True
        
    End Sub


    Hope that helps,
    ~tigeravatar
    Attached Files Attached Files

  3. #3
    Forum Contributor
    Join Date
    06-24-2009
    Location
    SCOTLAND
    MS-Off Ver
    Excel 2007
    Posts
    109

    Thumbs up Re: Select & copy spreadsheets to new folder

    This works a treat. Thankyou so much. I'll now try and customise it after I've understood the steps you've taken. Much obliged.

  4. #4
    Forum Contributor
    Join Date
    06-24-2009
    Location
    SCOTLAND
    MS-Off Ver
    Excel 2007
    Posts
    109

    Re: Select & copy spreadsheets to new folder

    Is it possible to split each selected worksheetand save as an individual file? For example, if 'A' and 'D' check boxes were checked then save 'A' as a workbook and 'D' as a workbook.

+ 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.2.0