Try:
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 Range("A2", Cells(Rows.Count, "A").End(xlUp)).SpecialCells(xlCellTypeVisible).Cells(1, 1).Row = 1 Then
MsgBox "No salt records."
nfm = nfm + 1
Stop
End If
...
End With
End With
End Sub
The macro assumes you have headers in row 1 and the data starts in row 2.
Bookmarks