LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
Sal Sal is offline
external usenet poster
 
Posts: 84
Default Merge Sheets

I have a workbook with a Sheet named Main Data. The sheet named Main Data, I
want to leave alone. The remaining 19 or 20 worksheets (the number of sheets
can vary), I would like to take the range A2 to the last row in AH that has
contents in it and paste those ranges from each worksheet into one new
worksheet so that they do not overlap. I put below the code that I have now
which works fine when I have 9 to 10 worksheets, but when I have 19 to 20
worksheets it doesnt work as well. Your help I appreciate. Thank you for
your suggestions.


Dim wksSum As Worksheet
Dim wks As Worksheet
Dim rCopy As Range
Dim lRow As Long

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

..DisplayAlerts = False
On Error Resume Next
ActiveWorkbook.Worksheets("RDBMergeSheet").Delete
On Error GoTo 0
..DisplayAlerts = True

Set wksSum = ActiveWorkbook.Worksheets.Add
wksSum.Name = "Summary Report"

wksSum.Range("A1:AH1").Value = Worksheets("Main Data").Range("A1:AH1").Value

For Each wks In ActiveWorkbook.Worksheets
With wks
If .Name < wksSum.Name And .Name < "Main Data" Then
Set rCopy = .Range("A2", .Cells(.Rows.Count, "AH").End(xlUp))

lRow = wksSum.Cells(wksSum.Rows.Count, "A").End(xlUp).Row
If lRow + rCopy.Rows.Count wksSum.Rows.Count Then
MsgBox "Not enough rows in Summary sheet to add sheet " & .Name
GoTo ExitTheSub
End If

rCopy.Copy
With wksSum.Cells(lRow + 1, "A")
..PasteSpecial xlPasteValues
..PasteSpecial xlPasteFormats
End With

wksSum.Cells(lRow + 1, "AH").Resize(rCopy.Rows.Count).Value = .Name
End If
End With
Next wks

ExitTheSub:
..CutCopyMode = False
..GoTo wksSum.Cells(1)
..ScreenUpdating = True
..EnableEvents = True
End With

End sub

 
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
Merge Sheets Iragalam Excel Discussion (Misc queries) 2 October 23rd 07 08:55 PM
how do i merge sheets jordousa06 Excel Discussion (Misc queries) 2 August 21st 07 09:26 AM
Merge wk sheets Sanj Excel Discussion (Misc queries) 0 February 22nd 07 01:16 PM
merge sheets lache Excel Discussion (Misc queries) 1 March 31st 06 03:38 PM
Merge two sheets BPR Excel Discussion (Misc queries) 1 March 16th 06 02:36 PM


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