Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 16
Default merge worksheets macro

I have a workbook that contains multiple identical worksheets and one
summary sheet. I am trying to add a new worksheet in the workbook
with the merged data from the identical sheets, but I have not been
able to exclude the summary worksheet.


'Start loop
For Each sht In wrk.Worksheets
'If worksheet in loop is the last one, stop execution
If sht.Index = wrk.Worksheets.Count Then
Exit For
End If
'Data range in worksheet - starts from second row as first
rows are the header rows in all worksheets
Set rng = sht.Range(sht.Cells(2, 1), sht.Cells(65536, 1).End
(xlUp).Resize(, colCount))
'Put data into the Master worksheet
mst.Cells(65536, 1).End(xlUp).Offset(1).Resize(rng.Rows.Count,
rng.Columns.Count).Value = rng.Value
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 236
Default merge worksheets macro

Unless i misunderstood, try this:
'Start loop
For Each sht In wrk.Worksheets

if if not sht.name = "YourSummarySheetNameHere" then 'If not
summary sheet, do the stuff, otherwise ignore.


'If worksheet in loop is the last one, stop execution
If sht.Index = wrk.Worksheets.Count Then
Exit For
End If
'Data range in worksheet - starts from second row as first
rows are the header rows in all worksheets
Set rng = sht.Range(sht.Cells(2, 1), sht.Cells(65536, 1).End
(xlUp).Resize(, colCount))
'Put data into the Master worksheet
mst.Cells(65536, 1).End(xlUp).Offset(1).Resize
(rng.Rows.Count,
rng.Columns.Count).Value = rng.Value

End if



On 17 July, 16:20, dhermus wrote:
I have a workbook that contains multiple identical worksheets and one
summary sheet. *I am trying to add a new worksheet in the workbook
with the merged data from the identical sheets, but I have not been
able to exclude the summary worksheet.

* * 'Start loop
* * For Each sht In wrk.Worksheets
* * * * 'If worksheet in loop is the last one, stop execution
* * * * If sht.Index = wrk.Worksheets.Count Then
* * * * * * Exit For
* * * * End If
* * * * 'Data range in worksheet - starts from second row as first
rows are the header rows in all worksheets
* * * * Set rng = sht.Range(sht.Cells(2, 1), sht.Cells(65536, 1).End
(xlUp).Resize(, colCount))
* * * * 'Put data into the Master worksheet
* * * * mst.Cells(65536, 1).End(xlUp).Offset(1).Resize(rng.Rows.Count,
rng.Columns.Count).Value = rng.Value


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 236
Default merge worksheets macro

oops - type, you surely don't need the 2 'ifs' in this:
if if not sht.name


On 17 July, 16:39, AB wrote:
Unless i misunderstood, try this:
* * *'Start loop
* * *For Each sht In wrk.Worksheets

* * * if if not sht.name = "YourSummarySheetNameHere" then 'If not
summary sheet, do the stuff, otherwise ignore.

* * * * *'If worksheet in loop is the last one, stop execution
* * * * *If sht.Index = wrk.Worksheets.Count Then
* * * * * * *Exit For
* * * * *End If
* * * * *'Data range in worksheet - starts from second row as first
*rows are the header rows in all worksheets
* * * * *Set rng = sht.Range(sht.Cells(2, 1), sht.Cells(65536, 1).End
*(xlUp).Resize(, colCount))
* * * * 'Put data into the Master worksheet
* * * * *mst.Cells(65536, 1).End(xlUp).Offset(1).Resize
(rng.Rows.Count,
*rng.Columns.Count).Value = rng.Value

* * *End if

On 17 July, 16:20, dhermus wrote:



I have a workbook that contains multiple identical worksheets and one
summary sheet. *I am trying to add a new worksheet in the workbook
with the merged data from the identical sheets, but I have not been
able to exclude the summary worksheet.


* * 'Start loop
* * For Each sht In wrk.Worksheets
* * * * 'If worksheet in loop is the last one, stop execution
* * * * If sht.Index = wrk.Worksheets.Count Then
* * * * * * Exit For
* * * * End If
* * * * 'Data range in worksheet - starts from second row as first
rows are the header rows in all worksheets
* * * * Set rng = sht.Range(sht.Cells(2, 1), sht.Cells(65536, 1).End
(xlUp).Resize(, colCount))
* * * * 'Put data into the Master worksheet
* * * * mst.Cells(65536, 1).End(xlUp).Offset(1).Resize(rng.Rows..Count,
rng.Columns.Count).Value = rng.Value- Hide quoted text -


- Show quoted text -


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,049
Default merge worksheets macro

you don't need to exit the FOR the way that you have done, just check that
the worksheet isn't the new sheet

FOR EACH sht IN wrk.Worksheets

IF sht.Name < mst.Name THEN

' copy the data
Set rng = sht.Range(sht.Cells(2, 1), sht.Cells(65536,
1).End(xlUp).Resize(, colCount ))
mst.Cells(65536, 1).End(xlUp).Offset(1).Resize(rng.Rows.Count,
rng.Columns.Count).Value = rng.Value

END IF

NEXT



Note: where does the variable colCount get its value?
maybe
colCount = sht.Range("A1").End(xlRight).Column




"dhermus" wrote in message
...
I have a workbook that contains multiple identical worksheets and one
summary sheet. I am trying to add a new worksheet in the workbook
with the merged data from the identical sheets, but I have not been
able to exclude the summary worksheet.


'Start loop
For Each sht In wrk.Worksheets
'If worksheet in loop is the last one, stop execution
If sht.Index = wrk.Worksheets.Count Then
Exit For
End If
'Data range in worksheet - starts from second row as first
rows are the header rows in all worksheets
Set rng = sht.Range(sht.Cells(2, 1), sht.Cells(65536, 1).End
(xlUp).Resize(, colCount))
'Put data into the Master worksheet
mst.Cells(65536, 1).End(xlUp).Offset(1).Resize(rng.Rows.Count,
rng.Columns.Count).Value = rng.Value


  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 16
Default merge worksheets macro

On Jul 17, 11:45*am, "Patrick Molloy"
wrote:
you don't need to exit the FOR the way that you have done, just check that
the worksheet isn't the new sheet

FOR EACH sht IN wrk.Worksheets

* * IF sht.Name < mst.Name THEN

* * * * ' copy the data
* * * * Set rng = sht.Range(sht.Cells(2, 1), sht.Cells(65536,
1).End(xlUp).Resize(, colCount ))
* * * * mst.Cells(65536, 1).End(xlUp).Offset(1).Resize(rng.Rows.Count,
rng.Columns.Count).Value = rng.Value

* * END IF

NEXT

Note: where does the variable colCount *get its value?
maybe
colCount = sht.Range("A1").End(xlRight).Column

"dhermus" wrote in message

...



I have a workbook that contains multiple identical worksheets and one
summary sheet. *I am trying to add a new worksheet in the workbook
with the merged data from the identical sheets, but I have not been
able to exclude the summary worksheet.


* *'Start loop
* *For Each sht In wrk.Worksheets
* * * *'If worksheet in loop is the last one, stop execution
* * * *If sht.Index = wrk.Worksheets.Count Then
* * * * * *Exit For
* * * *End If
* * * *'Data range in worksheet - starts from second row as first
rows are the header rows in all worksheets
* * * *Set rng = sht.Range(sht.Cells(2, 1), sht.Cells(65536, 1).End
(xlUp).Resize(, colCount))
* * * *'Put data into the Master worksheet
* * * *mst.Cells(65536, 1).End(xlUp).Offset(1).Resize(rng.Rows.Count,
rng.Columns.Count).Value = rng.Value- Hide quoted text -


- Show quoted text -


Thank you, this provided what I needed.


  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 16
Default merge worksheets macro

On Jul 17, 11:45*am, "Patrick Molloy"
wrote:
you don't need to exit the FOR the way that you have done, just check that
the worksheet isn't the new sheet

FOR EACH sht IN wrk.Worksheets

* * IF sht.Name < mst.Name THEN

* * * * ' copy the data
* * * * Set rng = sht.Range(sht.Cells(2, 1), sht.Cells(65536,
1).End(xlUp).Resize(, colCount ))
* * * * mst.Cells(65536, 1).End(xlUp).Offset(1).Resize(rng.Rows.Count,
rng.Columns.Count).Value = rng.Value

* * END IF

NEXT

Note: where does the variable colCount *get its value?
maybe
colCount = sht.Range("A1").End(xlRight).Column

"dhermus" wrote in message

...



I have a workbook that contains multiple identical worksheets and one
summary sheet. *I am trying to add a new worksheet in the workbook
with the merged data from the identical sheets, but I have not been
able to exclude the summary worksheet.


* *'Start loop
* *For Each sht In wrk.Worksheets
* * * *'If worksheet in loop is the last one, stop execution
* * * *If sht.Index = wrk.Worksheets.Count Then
* * * * * *Exit For
* * * *End If
* * * *'Data range in worksheet - starts from second row as first
rows are the header rows in all worksheets
* * * *Set rng = sht.Range(sht.Cells(2, 1), sht.Cells(65536, 1).End
(xlUp).Resize(, colCount))
* * * *'Put data into the Master worksheet
* * * *mst.Cells(65536, 1).End(xlUp).Offset(1).Resize(rng.Rows.Count,
rng.Columns.Count).Value = rng.Value- Hide quoted text -


- Show quoted text -


I found I have multiple hidden worksheets that I must also exclude
from my merge. Can you help with this statement?
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
Mail merge macro: select recipients from Excel during merge Worksmart Excel Programming 0 May 18th 08 06:37 PM
How to merge / combine several worksheets into one new worksheet without VBA / Macro? FOR EXPERTS [email protected] Excel Worksheet Functions 9 August 13th 07 04:19 AM
Macro to merge worksheets MikeCM Excel Programming 1 November 27th 06 05:09 PM
How to merge worksheets on a key - merge horizontally, that is [email protected] Excel Programming 4 November 4th 06 12:59 AM
Merge Worksheets Mark Jackson Excel Discussion (Misc queries) 1 June 9th 05 10:39 AM


All times are GMT +1. The time now is 08:12 PM.

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

About Us

"It's about Microsoft Excel"