If criteria1 does not exist then...

user125

New Member
Joined
Feb 20, 2020
Messages
31
Office Version
  1. 365
Platform
  1. Windows
Hi all,

This is a pretty common question but I can't seem to find a solution that works for me. I have the following code that is supposed to apply autofilter but if the criteria does not exist, I want it to turn off the filter and end if. However, the line
VBA Code:
If currentBoxRange.Offset(-1, 0).CurrentRegion.SpecialCells(xlCellTypeVisible).Rows.count = 1 Then
seems to run regardless of the criteria existing or not. Any help would be appreciated!

VBA Code:
Sheets("Missing_Files").Range("A2:E650").ClearContents
        currentBoxRange.Offset(-1, 0).AutoFilter Field:=6, Criteria1:="Missing Files Detected"
'the following line is where I am having difficulty
            If currentBoxRange.Offset(-1, 0).CurrentRegion.SpecialCells(xlCellTypeVisible).Rows.count = 1 Then
                    SARK.AutoFilterMode = False
                Else
                    currentBoxRange.Columns(3).Copy
                    Sheets("Missing_Files").Range("MissingFiles").Offset(1, 0).PasteSpecial xlPasteValues
                    SARK.AutoFilterMode = False
            End If

FYI: The above code is part of a larger procedure so I haven't added any of the variables that i have "dim" and no "end sub". All of that is mentioned in the actual procedure.
 

Excel Facts

Which lookup functions find a value equal or greater than the lookup value?
MATCH uses -1 to find larger value (lookup table must be sorted ZA). XLOOKUP uses 1 to find values greater and does not need to be sorted.

Forum statistics

Threads
1,214,424
Messages
6,119,404
Members
448,893
Latest member
AtariBaby

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top