Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 49
Default Select specific sheets and copy to new workbook

I am copying all worksheets that match a certain criteria to a new workbook.
The number of sheets will not be static every time the copy is run, thus
needing my array of sheets to be variable. How do you define the array of
sheets in a dynamic array as opposed to static?
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,276
Default Select specific sheets and copy to new workbook

Hi,
You can use something like this
'loop through all worksheets and copy the data to the DestSh
For Each sh In ActiveWorkbook.Worksheets

' I enter this statement to be sure I pick up only tabs starting with es or
cs
If LCase(Left(sh.Name, 2)) = "es" Or LCase(Left(sh.Name, 2)) = "cs"
Then

'Find the last row with data on the DestSh
Last = lastRow(Sheets("BackLog_Summary"))

'Fill in the range that you want to copy
Set CopyRng = sh.Range("A4:AZ6")

'Test if there enough rows in the DestSh to copy all the data
If Last + CopyRng.Rows.Count
Sheets("BackLog_Summary").Rows.Count Then
MsgBox "There are not enough rows in the Destsh"
GoTo ExitTheSub
End If

'This example copies values/formats, if you only want to copy the
'values or want to copy everything look at the example below
this macro
CopyRng.Copy
With Sheets("BackLog_Summary").Cells(Last + 1, "A")
.PasteSpecial xlPasteValues
.PasteSpecial xlPasteFormats
Application.CutCopyMode = False
End With

'Optional: This will copy the sheet name in the BA column
'Sheets("BackLog_Summary").Cells(Last + 1,
"BA").Resize(CopyRng.Rows.Count).Value = sh.Name

End If
Next

"jeremiah" wrote:

I am copying all worksheets that match a certain criteria to a new workbook.
The number of sheets will not be static every time the copy is run, thus
needing my array of sheets to be variable. How do you define the array of
sheets in a dynamic array as opposed to static?

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 49
Default Select specific sheets and copy to new workbook

Am rethinking my needs here because I need to copy each sheet to it's own
sheet in another workbook, would it make more sense to filter the sheets to
just the ones I need and then is it possible to save just the filtered sheets
to a new workbook?

"Eduardo" wrote:

Hi,
You can use something like this
'loop through all worksheets and copy the data to the DestSh
For Each sh In ActiveWorkbook.Worksheets

' I enter this statement to be sure I pick up only tabs starting with es or
cs
If LCase(Left(sh.Name, 2)) = "es" Or LCase(Left(sh.Name, 2)) = "cs"
Then

'Find the last row with data on the DestSh
Last = lastRow(Sheets("BackLog_Summary"))

'Fill in the range that you want to copy
Set CopyRng = sh.Range("A4:AZ6")

'Test if there enough rows in the DestSh to copy all the data
If Last + CopyRng.Rows.Count
Sheets("BackLog_Summary").Rows.Count Then
MsgBox "There are not enough rows in the Destsh"
GoTo ExitTheSub
End If

'This example copies values/formats, if you only want to copy the
'values or want to copy everything look at the example below
this macro
CopyRng.Copy
With Sheets("BackLog_Summary").Cells(Last + 1, "A")
.PasteSpecial xlPasteValues
.PasteSpecial xlPasteFormats
Application.CutCopyMode = False
End With

'Optional: This will copy the sheet name in the BA column
'Sheets("BackLog_Summary").Cells(Last + 1,
"BA").Resize(CopyRng.Rows.Count).Value = sh.Name

End If
Next

"jeremiah" wrote:

I am copying all worksheets that match a certain criteria to a new workbook.
The number of sheets will not be static every time the copy is run, thus
needing my array of sheets to be variable. How do you define the array of
sheets in a dynamic array as opposed to static?

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Copy data from specific sheets from one workbook to another mtuohey Excel Programming 0 August 28th 08 11:34 PM
Print sheets by "All Sheets in workbook, EXCEPT for specific named sheets". Possible? Corey Excel Programming 2 December 11th 06 01:35 AM
Copy specific Sheets and save them as a workbook Rock* Excel Programming 2 March 13th 06 08:28 PM
Sheets select method fails when workbook is opened by another workbook Mike Excel Programming 2 June 8th 04 04:17 AM
Copy select sheets to another Workbook Randy[_11_] Excel Programming 0 January 14th 04 05:06 PM


All times are GMT +1. The time now is 09:23 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"