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

Why are there 1,048,576 rows in Excel?
The Excel team increased the size of the grid in 2007. There are 2^20 rows and 2^14 columns for a total of 17 billion cells.
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,598
Messages
6,125,748
Members
449,258
Latest member
hdfarid

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