Ron de Bruin's Copy a range of each sheet

D

Don Guillett

Instead of asking us to follow a link, you should copy/paste the code that
YOU tried. I would image that you modified.
 
N

nc

Please find the code below, I ran it without any
modification


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 = Worksheets.Add
DestSh.Name = "Master"
For Each sh In ThisWorkbook.Worksheets
If sh.Name <> DestSh.Name Then
Last = LastRow(DestSh)

sh.Range("A1:C5").Copy DestSh.Cells(Last
+ 1, "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 + 1, "D").Value =
sh.Name
'This will copy the sheet name in the D
column if you want

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

Function LastRow(sh As Worksheet)
On Error Resume Next
LastRow = sh.Cells.Find(What:="*", _
After:=sh.Range("A1"), _
Lookat:=xlPart, _
LookIn:=xlFormulas, _
SearchOrder:=xlByRows, _
SearchDirection:=xlPrevious, _
MatchCase:=False).Row
On Error GoTo 0
End Function
 
R

Ron de Bruin

Hi nc

where have you copy/paste the code ?
You must copy it in a normal module

On which line do you get the error ?
 
N

nc

Hi Ron

Thanks for your reply.
I pasted the code in a normal module. I am not getting
an error, the "Master" sheet is created but with no data
except a cell containg the word Sheet1.

Kind regards
-----Original Message-----
Hi nc

where have you copy/paste the code ?
You must copy it in a normal module

On which line do you get the error ?

--
Regards Ron de Bruin
http://www.rondebruin.nl


"nc" <[email protected]> wrote in
message news:[email protected]...
 
Top