Ark68
Well-known Member
- Joined
- Mar 23, 2004
- Messages
- 4,641
- Office Version
- 365
- 2016
- Platform
- 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?
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