Select and copy specific sheets into a new workbook

cbg

New Member
Joined
Jun 22, 2009
Messages
2
Hi,

I've been around this issue for too long and I believe it's a simple thing to do but I'm just not getting it.

I've a userform (UserForm1) where the user selects the worksheets to copy into a new workbook by checking comboboxes.

After selecting the worksheets, the user click ok (CommandButton1) and it should:
  1. select the worksheets associated to the comboboxes;
  2. copy them;
  3. paste them into a new workbook without vba codes, command buttons and hidden rows and columns.
I was trying to do this like "baby steps" but I've got stuck here:

Code:
Private Sub CommandButton1_Click()
 
    Unload Me
 
    Dim WS As Worksheet
    Dim WB As Workbook
 
    If CheckBox1.Value = True And CheckBox2.Value = True And CheckBox3.Value = True Then
        Sheets(Array(Sheet1.Name, Sheet2.Name, Sheet3.Name)).Select
    ElseIf CheckBox1.Value = True And CheckBox2.Value = True Then
        Sheets(Array(Sheet1.Name, Sheet2.Name)).Select
    ElseIf CheckBox1.Value = True And CheckBox3.Value = True Then
        Sheets(Array(Sheet1.Name, Sheet3.Name)).Select
    ElseIf CheckBox2.Value = True And CheckBox3.Value = True Then
        Sheets(Array(Sheet2.Name, Sheet3.Name)).Select
    ElseIf CheckBox1.Value = True Then
        Sheets(Sheet1).Select
    ElseIf CheckBox2.Value = True Then
        Sheets(Sheet2).Select
    ElseIf CheckBox3.Value = True Then
        Sheets(Sheet3).Select
    ElseIf CheckBox1.Value = False And CheckBox2.Value = False And CheckBox3.Value = False Then
        Unload Me
        UserForm2.Show
        Exit Sub
    End If
 
    Set WB = Workbooks.Add
    
    For Each WS In ActiveWindow.SelectedSheets
        WS.Cells.Copy
        WS.[A1].PasteSpecial Paste:=xlValues
        Application.CutCopyMode = False
        WS.Activate
    Next WS
 
    WB.Application.Dialogs(xlDialogSaveAs).Show
 
End Sub

I've some example codes for copying without vba codes, command button and deleting hidden rows/columns.
My biggest issue is to select and copy specific worksheets (defined by the user in the moment) to a new workbook.

Should there be any clarification from my side, please don't hesitate to ask me.

Thank you for your support.
 

Excel Facts

Show numbers in thousands?
Use a custom number format of #,##0,K. Each comma after the final 0 will divide the displayed number by another thousand
I don't know why but I'm not able to edit my post.

I've found some mistakes: there are any comboboxes.
Everytime I refer comboboxes I want to say checkboxes.

Sorry.
 
Upvote 0

Forum statistics

Threads
1,215,521
Messages
6,125,305
Members
449,218
Latest member
Excel Master

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top