How to count in visible filtered selection, but not a specific color.

toondichter

New Member
Joined
Dec 28, 2022
Messages
2
Office Version
  1. 365
Platform
  1. Windows
Hello.

For a reasonably large sheet, I needed to count filtered data. Say for example I needed the amount we encounter the word HELLO in the filtered data.
On this site I've found code to count; and it works like a charm! It works so well, but I must admit I do not understand completely what is what.

VBA Code:
Function COUNTIFVISIBLE(r As Range, Crit) As Long
Dim s   As String, f As String, sRow As Long
s = r.Address: sRow = r.Row
If Not IsNumeric(Crit) Then Crit = """" & Crit & """"
f = "=sumproduct(subtotal(3,offset(" & s & ",row(" & s & ")-" & _
        sRow & ",,1)),--(" & s & "=" & Crit & "))"
COUNTIFVISIBLE = Evaluate(f)
End Function
Sub test()
MsgBox COUNTIFVISIBLE(Range("BQ2:BQ200"),"Delete")
End Sub
and
VBA Code:
WhatToCount = "HELLO"
CountHellos = COUNTIFVISIBLE(range("A2:A" & LR), WhatToCount)

Now the request changed and I need to count all the HELLO except when the text is red (HELLO)

I have been staring at the function for a while, but I have no idea if this can be implented.

Is there someone willing to help and think along with me?
 

Excel Facts

Does the VLOOKUP table have to be sorted?
No! when you are using an exact match, the VLOOKUP table can be in any order. Best-selling items at the top is actually the best.

Forum statistics

Threads
1,214,968
Messages
6,122,506
Members
449,089
Latest member
RandomExceller01

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top