Hi All,
My AutoFilter works providing there is data to be copied but I get an error if there is no data. I have tried to bypass the process if there is no data and show a "No data" msgbox but I can't get it to work. I have tried solutions from previous threads but for some reason I am still getting the same error when there is no data.
Any help will be appreciated.
Regards
Gob12345
My AutoFilter works providing there is data to be copied but I get an error if there is no data. I have tried to bypass the process if there is no data and show a "No data" msgbox but I can't get it to work. I have tried solutions from previous threads but for some reason I am still getting the same error when there is no data.
Any help will be appreciated.
Regards
Gob12345
Code:
'check the dates if all is OK run the filter
If Sheet1.Range("D3").Value >= Sheet1.Range("E3").Value Then
MsgBox " Your start value is wrong"
Exit Sub
Else
If Not IsEmpty(dDateTimeBegin) And Not IsEmpty(dDateTimeEnd) Then
'run the filter
With Rng
.AutoFilter Field:=2, Criteria1:=">=" & dDateTimeBegin, _
Operator:=xlAnd, Criteria2:="<=" & dDateTimeEnd
'If there is data then proceed, otherwise show msgbox
If Sheet2.Range("Database").SpecialCells(xlCellTypeVisible).Count > 1 Then 'THIS HIGHLIGHTS YELLOW IN DEBUG WHEN THERE IS NO DATA
'copy values
CopyFilter
'show all data
Showall
Else
MsgBox "No Data in Selected Range"
End If
End With