Replace the whole code or just add the red code
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
Dim S, r As Long, c As Long, i As Long, j As Long, k As Long, n As Long
Dim TRange As Range, Totals As Range, ws As Worksheet: Set ws = ActiveSheet
r = 2: Do Until ws.Cells(r + 1, 2) = "": r = r + 1: Loop
c = 15: Do Until ws.Cells(1, c + 1) = "": c = c + 1: Loop
Set TRange = ws.Range(ws.Cells(1, 1), ws.Cells(r, c))
Set Totals = ws.Range(ws.Cells(r + 2, 1), ws.Cells(r + 2, c))
Totals.Clear: S = Totals
ws.AutoFilterMode = False
If Target.Column < 20 And Target.Value <> "" Then
k = Target.Column
If k < 8 Then S(1, k) = Target.Value Else S(1, 7) = ws.Cells(1, k)
For i = 2 To r
If ws.Cells(i, Target.Column) = Target.Value Then
n = n + 1: S(1, 5) = S(1, 5) + ws.Cells(i, 5)
For j = 10 To 17:
If ws.Cells(i, j) <> "" Then
S(1, j) = S(1, j) + 1: End If
Next j
For j = 20 To 22: S(1, j) = S(1, j) + Val(ws.Cells(i, j)): Next j
End If: Next i
S(1, 5) = S(1, 5) / n
Totals = S: Totals.Interior.ColorIndex = 1: Totals.Font.ColorIndex = 2
ws.Cells(r + 2, 5).NumberFormat = "0.0"
ws.Cells(r + 2, 20).Resize(1, 3).NumberFormat = "$#,##0.00"
TRange.AutoFilter Field:=k, Criteria1:=Target.Value
End If
End Sub
Bookmarks