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.
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
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.![]()
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.
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks