MsgBox for Failed Filters

MattH1

Board Regular
Joined
Jul 15, 2016
Messages
174
Hey everyone,
I'm attempting to apply many different filters to a set of data and at the end have a message box of what filters yielded no results. Here is a sample of what the code looks like:

Code:
'Filters column V to only one criteria
        ActiveSheet.Range("$A1:$AZ" & RowCount).AutoFilter Field:=22, Criteria1:= _
        "A"
'If filter yields no results, go to next filter
If Range("$A1:A" & RowCount).SpecialCells(xlCellTypeVisible).Count = 1 Then
    GoTo Filter2
End If

'Code that copies visible cells over to a new sheet based on other constraints.

Filter2:
'Filters column V to only one criteria
        ActiveSheet.Range("$A1:$AZ" & RowCount).AutoFilter Field:=22, Criteria1:= _
         "B"
 'If filter yields no results, go to next filter
 If Range("$A1:A" & RowCount).SpecialCells(xlCellTypeVisible).Count = 1 Then
     GoTo Filter3
 End If

'Code that copies visible cells over to a new sheet based on other constraints.

Filter3:

This code continues for nearly 20 different filters. I was looking to create lines of code that would, at the END of this process, create a message box the states:
"The following filters yielded no results:
A
C
X"

How could I go about creating something like this? Any and all help is appreciated, I'm stumped because I can't figure out how to store all of them and output them in the message box (since I don't know how many results it will yield each time).
 

Excel Facts

Convert text numbers to real numbers
Select a column containing text numbers. Press Alt+D E F to quickly convert text to numbers. Faster than "Convert to Number"
Code:
Dim strvalue as String
If Range("$A1:A" & RowCount).SpecialCells(xlCellTypeVisible).Count = 1 Then
    strvalue = strvalue & vbCrLf & "A"
    GoTo Filter2
End If


'add in for rest of code also

MsgBox strvalue
 
Upvote 0
Thank you BarryL, I appreciate the help! Very simple command I just didn't think of, always appreciated!!
 
Upvote 0

Forum statistics

Threads
1,214,651
Messages
6,120,739
Members
448,989
Latest member
mariah3

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