Sub Filter()Dim Rng As Range, LRow As Long, VisibleRowCount As Long
Application.EnableEvents = False
Set Rng = Range("A17", Range("A" & Rows.Count).End(xlUp)).Resize(, 17)
LRow = Range("A" & Rows.Count).End(xlUp).Row
Rng.AdvancedFilter Action:=xlFilterInPlace, CriteriaRange:=Range("R2:X3"), Unique:=False
Range([A18], Cells(Rows.Count, "A")).SpecialCells(xlCellTypeVisible)(1).Select
VisibleRowCount = Rng.Columns(1).SpecialCells(xlCellTypeVisible).Cells.Count - 1
If VisibleRowCount = 0 Then
CCP.Caption = 0
CCI.Caption = "$0.00"
CPL.Caption = "$0.00"
CGL.Caption = "0.00%"
Else
CCP.Caption = WorksheetFunction.Subtotal(3, Range("A18:A" & LRow))
For Each Cl In Range("P18", Range("P" & Rows.Count).End(xlUp)).SpecialCells(xlVisible)
If Cl.Value > 0 Then Win = Win + 1
If Cl.Value < 0 Then Loss = Loss + 1
Next Cl
CCI.Caption = Win & "/" & Loss
CCI.Caption = Format(WorksheetFunction.Subtotal(1, Range("L18:L" & LRow)), "$#,0.00")
CPL.Caption = Format(WorksheetFunction.Subtotal(9, Range("P18:P" & LRow)), "$#,#0.00")
CGL.Caption = Format(WorksheetFunction.Subtotal(9, Range("P18:P" & LRow)) / WorksheetFunction.Subtotal(9, Range("L18:L" & LRow)), "0.00%")
End If
If WorksheetFunction.Subtotal(9, Range("P18:P" & LRow)) < 0 Then
CPL.ForeColor = vbRed
CGL.ForeColor = vbRed
ElseIf WorksheetFunction.Subtotal(9, Range("P18:P" & LRow)) > 0 Then
CPL.ForeColor = RGB(0, 176, 80)
CGL.ForeColor = RGB(0, 176, 80)
Else
CPL.ForeColor = vbBlack
CGL.ForeColor = vbBlack
End If
MyChart
Application.EnableEvents = True
End Sub