The code below filters a worksheet (ws_salt) of all rows that fall between an lower date (f_lr) and upper date (f_ur).
If Then code then determines whether the filter was returned empty.
In my testing on particular date rate that should be empty, displays empty after the filter is applied, but the "if worksheetFunction.Count(.Cells.SpecialCells(xlCellTypeVisible)) = 0" is failing. It is being treated as though there is filtered data, when it shouldn't. This worksheet does have data in it that doesn't match the filter criteria, so the filter appears to be working (it's coming back empty).
Private Sub uf2_create_Click()
Dim f_range As Range
Dim ui1 As String
nfm = 0 'no filtered material flag
With ws_salt
.AutoFilterMode = False 'turn off autofilter if on
f_lr = ws_sheet2.Cells(i, 11)
f_ur = ws_sheet2.Cells(i, 12)
last_col = .Range("A1").CurrentRegion.Columns.Count
Set f_range = .Range(.Cells(2, 1), .Cells(2, last_col))
With f_range
.AutoFilter field:=1, Criteria1:=">=" & f_lr, Operator:=xlAnd, Criteria2:="<=" & f_ur
If WorksheetFunction.Count(.Cells.SpecialCells(xlCellTypeVisible)) = 0 Then
MsgBox "No salt records."
nfm = nfm + 1
Stop
End If
...
End With
End With
I use the exact same on another similar worksheet (that doesn't yet contain any data let alone data meeting the criteria) and it works fine.
Bookmarks