Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 48
Default merging sheets to master sheet in a certain order

I am merging two sheets named "Previous Month" and "Current Month" together
on a master worksheet. I want them to sort to the master worksheet in that
order. What code do I need to add to my macro to accomplish this?

Thanks bunches in advance
marcia
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 360
Default merging sheets to master sheet in a certain order

Ron DeBruin has lots of good code on his site for stuff like this:
http://www.rondebruin.nl/tips.htm

Cliff Edwards
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 48
Default merging sheets to master sheet in a certain order

It is his code that I am using as part of my macro.
Here is what is happening:

'Delete "Previous" worksheet
Application.DisplayAlerts = False
On Error Resume Next
ActiveWorkbook.Worksheets("Previous").Delete
On Error GoTo 0
Application.DisplayAlerts = True

'Renames "Outstanding" to Previous
Sheets("Outstanding").Select
Sheets("Outstanding").Name = "Previous"


'Creates new "CurrentMonth" worksheet

Dim sh As Worksheet
Dim DestSh As Worksheet
Dim Last As Long
Dim shLast As Long
Dim CopyRng As Range
Dim StartRow As Long
Dim i, j As Integer

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


'Delete the sheet "CurrentMonth" if it exist
Application.DisplayAlerts = False
On Error Resume Next
ActiveWorkbook.Worksheets("CurrentMonth").Delete
On Error GoTo 0
Application.DisplayAlerts = True


'Add a worksheet with the name "CurrentMonth"
Set DestSh = ActiveWorkbook.Worksheets.Add
DestSh.Name = "CurrentMonth"

Then after "Current" is created, it goes directly into the merge of the two:

'Create "TotalForMonth" Worksheet

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

'Delete the sheet "TotalForMonth" if it exist
Application.DisplayAlerts = False
On Error Resume Next
ActiveWorkbook.Worksheets("TotalForMonth").Delete
On Error GoTo 0
Application.DisplayAlerts = True

'Add a worksheet with the name "TotalForMonth"
Set DestSh = ActiveWorkbook.Worksheets.Add
DestSh.Name = "TotalForMonth"



I am not sure where to alter the code to specify the order of the merge

thanks
marcia

"ward376" wrote:

Ron DeBruin has lots of good code on his site for stuff like this:
http://www.rondebruin.nl/tips.htm

Cliff Edwards

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 360
Default merging sheets to master sheet in a certain order

I don't see where any sheets are being merged - just sheets getting
deleted, created and renamed.

Are you running the code from the same workbook that the sheets are
in?

It looks like you're using "Outstanding" as the new "Previous", but
then you create a new "Current" sheet with no data - what do you want
to merge on the "Total" sheet?

If you post all your code and explain where the data is coming from
and exactly how you want to manipulate it, we can probably fix you up
pretty quickly.

Cliff Edwards




  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 48
Default merging sheets to master sheet in a certain order

The whole macro is really long, but I think that I have managed a workaround.
There may be a shorter way, but here is what is happening:

1. open workbook for "Nov"
2. save as "Dec"
3. delete Nov "Previous" items
4. change Nov month end outstanding to "Previous" for Dec.
5. create Dec's "CurrentMonth" items
6. copy CurrentMonth & Previous to "TotalForMonth" (this is where I need the
items to go onto the new sheet in the particular order because I am going to
determine which has been resolved during Dec and then create "outstanding"
for Dec.

My workaround on the "TotalForMonth" is this:

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

'Loop through the worksheets required
If IsError(Application.Match(sh.Name, _
Array(DestSh.Name, "CurrentMonth"),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(2), 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

'Optional: This will copy the sheet name in the H column
DestSh.Cells(Last + 1, "J").Resize(CopyRng.Rows.Count).Value =
sh.Name

End If

End If

Next


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


'Loop through the worksheets required
If IsError(Application.Match(sh.Name, _
Array(DestSh.Name, "Previous ), 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(2), 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

'Optional: This will copy the sheet name in the H column
DestSh.Cells(Last + 1, "J").Resize(CopyRng.Rows.Count).Value =
sh.Name

End If

End If

It seems to be working. I would like to know if there is a shorter way.

"ward376" wrote:

I don't see where any sheets are being merged - just sheets getting
deleted, created and renamed.

Are you running the code from the same workbook that the sheets are
in?

It looks like you're using "Outstanding" as the new "Previous", but
then you create a new "Current" sheet with no data - what do you want
to merge on the "Total" sheet?

If you post all your code and explain where the data is coming from
and exactly how you want to manipulate it, we can probably fix you up
pretty quickly.

Cliff Edwards







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
Paste all sheets into one master sheet Its me[_3_] Excel Worksheet Functions 5 August 3rd 09 03:30 AM
Master sheet to split sheets back to another master sheet FurRelKT Excel Programming 0 May 11th 06 09:28 PM
Inventory sheet to track, order & reduce quantity from master. drc536 New Users to Excel 2 October 23rd 05 05:36 PM
Make inventory sheet to track, order & reduce quantity from master drc536 Excel Worksheet Functions 1 October 23rd 05 05:35 PM
Allocate Files to Sheets and Build a Master Sheet which Summarises All Sheets hanuman Excel Programming 0 September 9th 03 11:23 AM


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