Vba countif visible cells

Shind

Board Regular
Joined
Feb 12, 2006
Messages
191
Hi,
Have the below code which keeps come back "Expected end of statement'. I dont know where its going wrong, can you help?

Application.WorksheetFunction.CountIf(Range("BQ2:BQ" & Range("BQ65536").End(xlUp).Row).SpecialCells(xlCellTypeVisible)),"delete")

Thanks
 

Excel Facts

Fastest way to copy a worksheet?
Hold down the Ctrl key while dragging tab for Sheet1 to the right. Excel will make a copy of the worksheet.
Hi,

Try,

Code:
MsgBox Application.WorksheetFunction.CountIf(Range("BQ2:BQ" & Range("BQ65536"). _
    End(xlUp).Row).SpecialCells(xlCellTypeVisible), "delete")

or store the results in a variable.
 
Upvote 0
Hi sorry for the late response.

Heres the code im using.

Just filtering a column.

Selection.AutoFilter
Selection.AutoFilter Field:=7, Criteria1:=">30", Operator:=xlAnd

the as above my problem code. just want to know how many equals "delete"
 
Upvote 0
these are the three codes iv'e tried. Nonhe of which work.

Code1

MsgBox Application.WorksheetFunction.CountIf(Range("BQ2:BQ" & Range("BQ65536").End(xlUp).Row).SpecialCells(xlCellTypeVisible), "Delete")

Code 2

MsgBox Application.WorksheetFunction.CountIf(Columns("BQ").SpecialCells(xlCellTypeVisible), "Delete")

Code 3
MsgBox Application.WorksheetFunction.CountIf(Range("BQ2:BQ200").SpecialCells(xlCellTypeVisible), "Delete")
 
Upvote 0
Figured something out Krishna, the code you provided does work BUT.... not when i have the filters on.
is there any way around this
 
Upvote 0
Hi,

Sory for the late reply.

Try,

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

HTH
 
Upvote 0

Forum statistics

Threads
1,223,832
Messages
6,174,905
Members
452,590
Latest member
CraiginColorado

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