VBA help - copy array of sheets to new workbook using dictionary

Mallesh23

Well-known Member
Joined
Feb 4, 2009
Messages
976
Office Version
  1. 2010
Platform
  1. Windows
Hi Team,

I want copy all sheets except Sheet1 to New workbook and want to save that workbook.
using dictionary approach.

Thisworkbook.Sheets(Array("SheetName1", "SheetName2", "SheetName3", "SheetName4")).Copy



VBA Code:
Sub Copyallsheets()

Dim ws As Worksheet
Dim dict As New Scripting.dictionary

'Add sheetname to dictionary for copying

For Each ws In ThisWorkbook.Worksheets

    If UCase(ws.Name) <> "SHEET1" Then
           
        dict.Add ws.Name, Empty
   
    End If

Next ws

'Add new workbook and copy sheets

Dim nwbk As Workbook
Set nwbk = Workbooks.Add

ThisWorkbook.Sheets([B]Array(dict.Keys))[/B].Copy After:=nwbk.Worksheets("Sheet1")

'Thisworkbook.Sheets(Array("SheetName1", "SheetName2", "SheetName3", "SheetName4")).Copy


End Sub

Thanks
mg
 

Excel Facts

What is the shortcut key for Format Selection?
Ctrl+1 (the number one) will open the Format dialog for whatever is selected.
How about
VBA Code:
ThisWorkbook.Sheets(dict.Keys).Copy After:=nwbk.WorkSheets("Sheet1")
 
Upvote 0
Hi Fluff,

So sweet one line code, Thanks for your help, it worked (y)


Thanks
mg
 
Upvote 0
You're welcome & thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,215,064
Messages
6,122,936
Members
449,094
Latest member
teemeren

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