Counta Of Filtered Data - Errors In VBA Formula (Poor adaptation)

Ark68

Well-known Member
Joined
Mar 23, 2004
Messages
4,641
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
Clearly I'm having, in addition to many things, working with filtered data. This may be related to this post.

Consider the code attached. The line in red, unsurprisingly, is giving me an error ("Expected: expression") I am trying to calculate the number of instances of the value "OK" from column J of a filtered worksheet. I found this solution with a Google search, but I had to adapt it from the demonstrated worksheet formula to a VBA formula. Clearly I failed. Woul anyone like to help me correct my adaptation to work for me?

Rich (BB code):
Sub inspect1()
    Dim txt_model As String
    Dim wb_catalogue As Workbook
    Dim ws_ifm As Worksheet
    Dim d As Double
    Dim lstrow As Long
    Dim f_rowcnt As Long
    Dim mccntok As Long
    
    Set wb_catalogue = ThisWorkbook
    Set ws_ifm = wb_catalogue.Worksheets("IFM (M)")
    
    With ws_ifm
        .AutoFilterMode = False
        lstrow = .Cells.Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
        Debug.Print "Last row: " & lstrow
        txt_model = InputBox("Enter Model Name: ", "Index")
        If txt_model = "" Then Exit Sub
        .Range("A2").AutoFilter Field:=1, Criteria1:=txt_model
        Stop
        f_rowcnt = [subtotal(103,A:A)] 'thanks mumps
        Debug.Print f_rowcnt
        mccntok = worksheetfunction(sumproduct(subtotal(3,offset("J3:J" & lstrow)-min(row("J3:J" & lstrow)),,1,)),N("J3:J"&lstrow)="OK")))
    End With
End Sub
 

Excel Facts

Can you AutoAverage in Excel?
There is a drop-down next to the AutoSum symbol. Open the drop-down to choose AVERAGE, COUNT, MAX, or MIN
Hi Skyybot, thank you for your input. If I understand what you are pointing out, I updated that line as:
Rich (BB code):
mccntok = worksheetfunction(sumproduct(subtotal(3,offset(.Range("J3:J" & lstrow))-min(row(.Range("J3:J" & lstrow))),,1,)),N(.Range("J3:J" & lstrow))="OK"))

But still get the error. The error is highlighted in blue
 
Upvote 0
Correction?
Rich (BB code):
mccntok = worksheetfunction.sumproduct(subtotal(3,offset(.Range("J3:J" &amp; lstrow))-min(row(.Range("J3:J" &amp; lstrow))),,1,<u><span><strong>))</strong></span></u>,N(.Range("J3:J" &amp; lstrow))="OK"))
 
Upvote 0
VBA Code:
mccntok = Application.WorksheetFunction.Subtotal(3, Range("A1:A10")) ' <-Change A1:A10 to your Range
 
Upvote 0

Forum statistics

Threads
1,225,400
Messages
6,184,758
Members
453,254
Latest member
topeb

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