sakthi santhanam
New Member
Hi here I have added the code where I autofilter a column and based on that count the value. The countif works for the first value and but for the second time after the autofilter it throws an error as "Unable to get the countif property of the worksheetfunction class.
Here for the first value in the list box the filter happens correctly and gets the count of the range based on the criteria. But for the second value in the listbox it filters as per the value but when it comes to the l1 it shows the error. If criteria is not satisfied then it should return 0 that I get for the first run but for the second run it shows the error.
Regards,
sakthi santhanam
Code:
For Each a In xlws11.Range("F2:F" & xlws11.UsedRange.Rows.Count) ' acc wise
If Not IsEmpty(a.Value) Then
UserForm9.ListBox1.AddItem (a.Value)
If UserForm9.ComboBox1.Value = "Alert" Then
lw = xlws2.Rows.Count
xlws2.UsedRange.AutoFilter Field:=9, Criteria1:=a.Value
Set cell1 = xlws2.Range("K3:K" & lw).SpecialCells(xlCellTypeVisible).SpecialCells(xlCellTypeConstants)
[COLOR=#ff0000]l1 = Application.WorksheetFunction.CountIf(cell1, "No") 'Error at this line[/COLOR]
xlws2.autofiltermode = false
end if
end if
next a
Here for the first value in the list box the filter happens correctly and gets the count of the range based on the criteria. But for the second value in the listbox it filters as per the value but when it comes to the l1 it shows the error. If criteria is not satisfied then it should return 0 that I get for the first run but for the second run it shows the error.
Regards,
sakthi santhanam