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.