Try this code
Option Explicit
Sub update_sheets()
Dim i As Long, lrow As Long, j As Long
Application.ScreenUpdating = False
For i = 1 To Worksheets.Count
With Worksheets(i)
If .Name = "Q1" Or .Name = "Q2" Or .Name = "Q3" Or .Name = "Q4" Or .Name = "YEARLY" Then
lrow = .Range("A" & .Rows.Count).End(xlUp).Row
If lrow > 1 Then .Range("A2:C" & lrow).ClearContents
End If
End With
Next i
For i = 1 To Worksheets.Count
With Worksheets(i)
If .Name <> "Q1" And .Name <> "Q2" And .Name <> "Q3" And .Name <> "Q4" And .Name <> "YEARLY" Then
lrow = .Range("A" & .Rows.Count).End(xlUp).Row
If lrow > 1 Then .Range("A2:B" & lrow).Copy Worksheets("YEARLY").Range("A" & Rows.Count).End(xlUp).Offset(1, 0)
End If
If .Name = "Jan" Or .Name = "Feb" Or .Name = "March" Then
lrow = .Range("A" & .Rows.Count).End(xlUp).Row
If lrow > 1 Then .Range("A2:B" & lrow).Copy Worksheets("Q1").Range("A" & Rows.Count).End(xlUp).Offset(1, 0)
ElseIf .Name = "April" Or .Name = "May" Or .Name = "June" Then
lrow = .Range("A" & .Rows.Count).End(xlUp).Row
If lrow > 1 Then .Range("A2:B" & lrow).Copy Worksheets("Q2").Range("A" & Rows.Count).End(xlUp).Offset(1, 0)
ElseIf .Name = "July" Or .Name = "Aug" Or .Name = "Sept" Then
lrow = .Range("A" & .Rows.Count).End(xlUp).Row
If lrow > 1 Then .Range("A2:B" & lrow).Copy Worksheets("Q3").Range("A" & Rows.Count).End(xlUp).Offset(1, 0)
ElseIf .Name = "Oct" Or .Name = "Nov" Or .Name = "Dec" Then
lrow = .Range("A" & .Rows.Count).End(xlUp).Row
If lrow > 1 Then .Range("A2:B" & lrow).Copy Worksheets("Q4").Range("A" & Rows.Count).End(xlUp).Offset(1, 0)
End If
End With
Next i
For i = 1 To Worksheets.Count
With Worksheets(i)
If .Name = "Q1" Or .Name = "Q2" Or .Name = "Q3" Or .Name = "Q4" Or .Name = "YEARLY" Then
.Sort.SortFields.Clear
.Sort.SortFields.Add Key:=Range("A:A") _
, SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
.Sort.SortFields.Add Key:=Range("B:B") _
, SortOn:=xlSortOnValues, Order:=xlDescending, DataOption:=xlSortNormal
With .Sort
.SetRange Range("A:C")
.Header = xlYes
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
lrow = .Range("A" & .Rows.Count).End(xlUp).Row
If lrow > 1 Then
.Range("C2:C" & lrow).FormulaR1C1 = "=COUNTIF(C[-2],RC[-2])"
.Range("C2:C" & lrow).Value = .Range("C2:C" & lrow).Value
End If
For j = lrow To 2 Step -1
If .Range("A" & j).Value = .Range("A" & j - 1).Value Then .Rows(j).Delete
Next j
End If
End With
Next i
MsgBox "Summary complete"
Application.ScreenUpdating = True
End Sub
Copy the Excel VBA code
Select the workbook in which you want to store the Excel VBA code
Hold the Alt key, and press the F11 key, to open the Visual Basic Editor
Choose Insert | Module
Where the cursor is flashing, choose Edit | Paste
To run the Excel VBA code:
Choose View | Macros
Select a macro in the list, and click the Run button
Bookmarks