Nothing wrong with Malcolm's addition, but I noticed a few other things I didn't like in the final layout; there was a blank column; fonts varied; and the columns were not ordered. This version addresses all of those
Public Sub SummarizeData()
Dim ws As Worksheet
Dim firstrow As Long
Dim lastrow As Long
Dim lastcol As Long
Dim numrows As Long
Dim i As Long
Application.ScreenUpdating = False
Set ws = Worksheets.Add
With Worksheets("RawData")
firstrow = .Range("A1").End(xlDown).Row
lastrow = .Cells(.Rows.Count, "A").End(xlUp).Row
numrows = lastrow - firstrow + 1
'get unique list of drivers
.Cells(firstrow, "C").Resize(numrows).Copy ws.Range("A1")
ws.Range(ws.Range("A1"), ws.Range("A1").End(xlDown)).RemoveDuplicates Columns:=1, Header:=xlNo
'get unique list of Zone
.Cells(firstrow, "N").Resize(numrows).Copy ws.Range("B1")
ws.Range(ws.Range("B1"), ws.Cells(ws.Rows.Count, "B").End(xlUp)).RemoveDuplicates Columns:=1, Header:=xlNo
'get unique list of Pk or Del?
.Cells(firstrow, "O").Resize(numrows).Copy ws.Range("C1")
ws.Range(ws.Range("C1"), ws.Cells(ws.Rows.Count, "C").End(xlUp)).RemoveDuplicates Columns:=1, Header:=xlNo
End With
With ws
'merge Zone and Pk or Del? lists and setup as headings
lastrow = .Cells(.Rows.Count, "B").End(xlUp).Row
numrows = .Cells(.Rows.Count, "C").End(xlUp).Row - 1
.Range(.Range("C2"), .Cells(.Rows.Count, "C").End(xlUp)).Cut Destination:=.Cells(lastrow, "B").Resize(numrows)
lastrow = .Cells(.Rows.Count, "B").End(xlUp).Row
.Range("B2").Resize(lastrow - 1).Copy
.Range("B1").PasteSpecial Paste:=xlPasteAll, Operation:=xlNone, SkipBlanks:=False, Transpose:=True
.Range("B2").Resize(lastrow - 1).ClearContents
'setup formula to count instances
lastrow = .Cells(.Rows.Count, "A").End(xlUp).Row
lastcol = .Cells(1, .Columns.Count).End(xlToLeft).Column
With .Range("A1").Resize(lastrow, lastcol)
With .Font
.Name = "Calibri"
.Size = 11
End With
End With
With .Range("B2").Resize(lastrow - 1, lastcol - 1)
.FormulaR1C1 = "=COUNTIFS(RawData!C3,RC1,RawData!C14,R1C)+COUNTIFS(RawData!C3,RC1,RawData!C15,R1C)"
.Value = .Value
.NumberFormat = "General;;"
End With
.Columns("A:A").EntireColumn.AutoFit
'sort columns and remove blanks
.Sort.SortFields.Clear
.Sort.SortFields.Add Key:=.Range("B1").Resize(, lastcol - 1), _
SortOn:=xlSortOnValues, _
Order:=xlAscending, _
DataOption:=xlSortNormal
With .Sort
.SetRange ws.Range("B1").Resize(lastrow - 1, lastcol - 1)
.Header = xlGuess
.MatchCase = False
.Orientation = xlLeftToRight
.SortMethod = xlPinYin
.Apply
End With
For i = lastcol To 2 Step -1
If .Cells(1, i).Value = "" Then
.Columns(i).Delete
Else
Exit For
End If
Next i
End With
Application.ScreenUpdating = True
End Sub