Sub ConsDataByMonth()
'Confirm the active tab is where the data is to consolidated.
If MsgBox("Please click ""Yes"" if the data is to be consolidated on the " _
& ActiveSheet.Name & " tab.", _
vbYesNo + vbExclamation, "Data Consolidation Editor") = vbNo Then
MsgBox "Select the tab you wish to have the data consolidated on and try again." _
, vbInformation, "Data Consolidation Editor"
Exit Sub
End If
Application.ScreenUpdating = False
'Remove any existing filters
If ActiveSheet.AutoFilterMode Then
ActiveSheet.AutoFilterMode = False
End If
'Declare variables
Dim lngLastRow As Long
Dim wSheet As Worksheet
Dim rCopy, rPaste As Range
lngLastRow = Cells(Rows.Count, "A").End(xlUp).Row
If lngLastRow > 1 Then
ActiveSheet.Range("A2:G" & lngLastRow).ClearContents
End If
For Each wSheet In Worksheets
If wSheet.Name <> ActiveSheet.Name Then
With wSheet
Set rCopy = .Range("A2", .Cells(Rows.Count, "G").End(xlUp))
End With
Set rPaste = ActiveSheet.Cells(Rows.Count, "A").End(xlUp)(2, 1)
rCopy.Copy
rPaste.PasteSpecial Paste:=xlValues, Paste:=xlPasteFormats
Application.CutCopyMode = False
End If
Next wSheet
With ActiveSheet
'Set the autofilter
.Range("A1:G1").AutoFilter
'Hide all rows that are NOT to be deleted
.Columns("G").AutoFilter Field:=7, Criteria1:="Yes"
.Rows("1").EntireRow.Hidden = True
'Delete all visible data rows in Column G
.Columns("G").SpecialCells(xlCellTypeVisible).EntireRow.Delete
'Remove filter from A1:G1
.AutoFilterMode = False
'Unhide Row 1.
.Rows("1").EntireRow.Hidden = False
'Autofit the dataset
.Columns("A:G").AutoFit
End With
Application.ScreenUpdating = True
ActiveSheet.Range("A1").Select
End Sub