Ark68
Well-known Member
- Joined
- Mar 23, 2004
- Messages
- 4,566
- Office Version
- 365
- 2016
- Platform
- Windows
Consider the code below.
Worksheet 'ws_sand' is filtered (column A) to include all dates between two date ranges (f_lr & f_ur).
Rows 1 and 2 are static header rows, Row 2 holds the column (field) names.
For the most part this is working, except when there are no dates found as a result of the filter. There is no data displayed below row 2.
The line purple is meant to identify this scenario, but it is not. In my testing, when there are no rows returned as part of the filter, I am NOT getting the msgbox displayed and the nfm counter is not increased.
What must I do to improve my code to have this work as desired?
Worksheet 'ws_sand' is filtered (column A) to include all dates between two date ranges (f_lr & f_ur).
Rows 1 and 2 are static header rows, Row 2 holds the column (field) names.
For the most part this is working, except when there are no dates found as a result of the filter. There is no data displayed below row 2.
The line purple is meant to identify this scenario, but it is not. In my testing, when there are no rows returned as part of the filter, I am NOT getting the msgbox displayed and the nfm counter is not increased.
What must I do to improve my code to have this work as desired?
Rich (BB code):
With ws_sand
.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
End With
With ws_sand
If .Range("A2", .Cells(.Rows.Count, "A").End(xlUp)).SpecialCells(xlCellTypeVisible).Cells(1, 1).Row = 1 Then
MsgBox "No sand records.", vbInformation, "NO SAND USED"
nfm = nfm + 1
End If
End With
End With