Error Message?

H

hce

Hi

Is it possible to write a code that will generate an error message i
the filter returns 0 records? I wrote a macro to do the filter based o
the values entered in specified cells but the problem here is that som
of the criteria used might not be available hence resulting in n
records being filtered/shown... so i would like to generate an erro
message before the user sees the empty database...

cheer
 
D

Dave Peterson

If the number of visible cells in the first column is 1 (only the header), then
that means that there was no criteria that matched:

With ActiveSheet.AutoFilter.Range
If .Columns(1).Cells.SpecialCells(xlCellTypeVisible).Count = 1 Then
'no visible cells, except for the header
'error message here
Else
'do what you want
End if
end with
 
Top