Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 201
Default Can I copy just the visible sheets?

I realise I can make the sheets I want to copy visible, then copy them as per
below (using variables for sheet names)

Sheets(Array(CCRFsheet2, CCRFsheet3, CCRFsheet4a, CCRFsheet6,
CCRFsheet7a, CCRFsheet7b, CCRFsheet8, CCRFsheet9)).Copy

But is it possible to write a macro that will work out what sheets are
visible and then only copy those sheets to another WorkBook?

--
Trefor

  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 22,906
Default Can I copy just the visible sheets?

Trefor

No error trapping and Book4.xls must be open.


Private Sub Visble_Only()
Dim ws As Worksheet
For Each ws In ActiveWorkbook.Sheets
If ws.Visible = True Then
ws.Copy Befo=Workbooks("Book4.xls").Sheets(1)
End If
Next
End Sub


Gord Dibben MS Excel MVP


On Sat, 2 Sep 2006 10:43:01 -0700, Trefor wrote:

I realise I can make the sheets I want to copy visible, then copy them as per
below (using variables for sheet names)

Sheets(Array(CCRFsheet2, CCRFsheet3, CCRFsheet4a, CCRFsheet6,
CCRFsheet7a, CCRFsheet7b, CCRFsheet8, CCRFsheet9)).Copy

But is it possible to write a macro that will work out what sheets are
visible and then only copy those sheets to another WorkBook?


  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 201
Default Can I copy just the visible sheets?

Gord,

Thankyou for your reply. Not quite what I was after, but close enough. This
creates my sheets in reverse order in the new workbook and leaves the default
Sheet1, Sheet2, etc.

I modified and expanded your reponse, I am not sure if there is a better way
of doing this, but this works for me:

Dim ws As Worksheet, ws1 As Worksheet, x As Integer
Workbooks.Add
ActiveWorkBook.name
x = 0
For Each ws In ThisWorkbook.Sheets
If ws.Visible = True And InStr(ws.name, "Introduction") = 0 And
InStr(ws.name, "New Site Request") = 0 Then
x = x + 1
If x = 1 Then
ws.Copy After:=ActiveWorkBook.Sheets(1)
Set ws1 = ws
Else
ws.Copy After:=ActiveWorkBook.Sheets(ws1.name)
Set ws1 = ws
End If
End If
Next

For Each ws In ActiveWorkBook.Sheets
If Left(ws.name, 5) = "Sheet" Then
Application.DisplayAlerts = False
ws.Delete
Application.DisplayAlerts = True
End If
Next

ActiveWorkBook.SaveAs
FileName:=ThisWorkbook.Sheets(CCRFsheet2).Cells(10 0, "A").Value, _
FileFormat:=xlNormal, Password:="", WriteResPassword:="",
ReadOnlyRecommended:=False, CreateBackup:=False


--
Trefor


"Gord Dibben" wrote:

Trefor

No error trapping and Book4.xls must be open.


Private Sub Visble_Only()
Dim ws As Worksheet
For Each ws In ActiveWorkbook.Sheets
If ws.Visible = True Then
ws.Copy Befo=Workbooks("Book4.xls").Sheets(1)
End If
Next
End Sub


Gord Dibben MS Excel MVP


On Sat, 2 Sep 2006 10:43:01 -0700, Trefor wrote:

I realise I can make the sheets I want to copy visible, then copy them as per
below (using variables for sheet names)

Sheets(Array(CCRFsheet2, CCRFsheet3, CCRFsheet4a, CCRFsheet6,
CCRFsheet7a, CCRFsheet7b, CCRFsheet8, CCRFsheet9)).Copy

But is it possible to write a macro that will work out what sheets are
visible and then only copy those sheets to another WorkBook?



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 and past to different sheets zgclub Excel Discussion (Misc queries) 4 February 9th 06 11:58 AM
copy workbook sheets? L. Setting up and Configuration of Excel 3 November 29th 05 03:30 AM
Copy formatted in several sheets of a workbook Emece Excel Worksheet Functions 1 September 28th 05 10:10 PM
Copy with link between sheets - all the formats dissapear?!? Kathrine Excel Discussion (Misc queries) 1 February 4th 05 03:45 PM
Copy & Paste Visible Cells with Formulas Ricky Excel Worksheet Functions 5 January 27th 05 05:37 PM


All times are GMT +1. The time now is 11:10 AM.

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

About Us

"It's about Microsoft Excel"