LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default VBA Help on Not Copying Specific Worksheets


Hi,

In the following function below I am trying to modify Ron de Bruin
function for merge cells from all or some worksheets and am running
into problems with the entry: For Each sh In Sheets(Array("Sheet1",
Sheet2" etc.). I have 24 tabs that can be used for data entry and 2
reserved worksheets for instructions and other macro buttons. You see
that I tried a couple of options that are commented out. The error
message is a runtime error code 9 and hilites the code in yellow
below.

Could someone please assist in educating me on the correct way or other
options available?

Thanks in advance


'Copy a range of each sheet

'This example use the function LastRow


Sub Test1()
Dim sh As Worksheet
Dim DestSh As Worksheet
Dim Last As Long

On Error Resume Next
If Len(ThisWorkbook.Worksheets.Item("Master").Name) = 0 Then
On Error GoTo 0
Application.ScreenUpdating = False
Set DestSh = ThisWorkbook.Worksheets.Add
DestSh.Name = "Master"
'For Each sh In ThisWorkbook.Worksheets
'If sh.Name < DestSh.Name Then
'If Left(sh.Name, 4) = "hub" Then

For Each sh In Sheets(Array("hub 1", "hub 2", "hub 3", "hub 4", "hub
6", "hub 7", "hub 8", "hub 9", "hub 10", "hub 11", "hub 12", "hub 13",
"hub 14", "hub 15", "hub 16", "hub 17", "hub 18", "hub 19", "hub 20",
"hub 21"))
Last = LastRow(DestSh)

sh.Range("A1:F295").Copy DestSh.Cells(Last + 2, "A")
'Instead of this line you can use the code below to
copy only the values
'or use the PasteSpecial option to paste the format
also.


'With sh.Range("A1:C5")
'DestSh.Cells(Last + 1, "A").Resize(.Rows.Count, _
'.Columns.Count).Value = .Value
'End With


'sh.Range("A1:C5").Copy
'With DestSh.Cells(Last + 1, "A")
' .PasteSpecial xlPasteValues, , False, False
' .PasteSpecial xlPasteFormats, , False, False
' Application.CutCopyMode = False
'End With

DestSh.Cells(Last + 2, "C").Value = sh.Name
'This will copy the sheet name in the D column if you
want

'End If
Next
DestSh.Cells(1).Select
Application.ScreenUpdating = True
Else
MsgBox "The sheet Master already exist"
End If
End Sub


--
greengrass
------------------------------------------------------------------------
greengrass's Profile: http://www.excelforum.com/member.php...o&userid=23119
View this thread: http://www.excelforum.com/showthread...hreadid=542694

 
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
Macro for copying specific rows from various worksheets to summary rsmith Excel Discussion (Misc queries) 6 January 13th 09 03:27 AM
Copying specific rows Eric Montelongo Excel Worksheet Functions 1 June 20th 06 08:08 PM
print specific worksheets in specific order. jarvo Excel Programming 1 April 11th 06 11:05 AM
Copying data to specific columns chalky Excel Programming 2 June 6th 05 01:05 PM
Stop Copying at Specific Row smandula Excel Programming 7 March 28th 05 02:17 PM


All times are GMT +1. The time now is 02:04 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"