LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #9   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 50
Default Copy range on multiple sheets into one sheet

That did it. Thanks for your help!

Ron de Bruin wrote:
Hi Joe

Try this one together with the lastrow function.
It will copy from row 2 till the last row with data of each sheet

Sub CopyDataWithoutHeaders()
Dim sh As Worksheet
Dim DestSh As Worksheet
Dim Last As Long
Dim shLast As Long
Dim CopyRng As Range
Dim StartRow As Long

With Application
.ScreenUpdating = False
.EnableEvents = False
End With

'Clear the data on "Exceptions", it will not delete row 1 this example
Set DestSh = ActiveWorkbook.Worksheets("Exceptions")
DestSh.Rows("2:" & Rows.Count).Clear

'Fill in the start row
StartRow = 2

'loop through all worksheets and copy the data to the DestSh
For Each sh In ActiveWorkbook.Worksheets

'Loop through all worksheets except the RDBMerge worksheet and the
'Information worksheet, you can ad more sheets to the array if you want.
If IsError(Application.Match(sh.Name, _
Array(DestSh.Name, "Exceptions"), 0)) Then

'Find the last row with data on the DestSh and sh
Last = LastRow(DestSh)
shLast = LastRow(sh)

'If sh is not empty and if the last row = StartRow copy the CopyRng
If shLast 0 And shLast = StartRow Then

'Set the range that you want to copy
Set CopyRng = sh.Range(sh.Rows(StartRow), sh.Rows(shLast))

'Test if there enough rows in the DestSh to copy all the data
If Last + CopyRng.Rows.Count DestSh.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 below example 1 on this page
CopyRng.Copy
With DestSh.Cells(Last + 1, "A")
.PasteSpecial xlPasteValues
.PasteSpecial xlPasteFormats
Application.CutCopyMode = False
End With

End If

End If
Next

ExitTheSub:

Application.GoTo DestSh.Cells(1)

'AutoFit the column width in the DestSh sheet
DestSh.Columns.AutoFit

With Application
.ScreenUpdating = True
.EnableEvents = True
End With
End Sub

Thanks!

[quoted text clipped - 10 lines]

Application.EnableEvents = True


--
Message posted via http://www.officekb.com

 
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
Conditional copy from multiple sheets to one sheet Pam[_3_] Excel Programming 2 April 30th 09 06:23 PM
Conditionally copy from multiple sheets to one sheet Pam[_3_] Excel Programming 2 April 29th 09 10:30 PM
Copy data from multiple sheets into new sheet Angie Excel Worksheet Functions 0 June 5th 07 10:53 PM
How do I copy setting from one sheet to multiple sheets in Excel? danam6 Excel Discussion (Misc queries) 1 April 27th 06 09:05 AM
copy data in one sheet to multiple sheets in same workbook BrianMultiLanguage Excel Worksheet Functions 4 July 27th 05 07:26 PM


All times are GMT +1. The time now is 03:56 PM.

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"