VBA Message if Conditions do not exist

KatKitKat

New Member
Joined
Apr 27, 2022
Messages
33
Office Version
  1. 365
Platform
  1. Windows
Hi,

I have a spreadsheet where I added several macro buttons that the end users can use to filter data across various columns. I also added a macro button to unfilter the spreadsheet since there are so many columns. My question is, is there a way to add a pop-up message to the code so if the spreadsheet does not have any filters on (all columns and rows not hidden? Right now, if there are no filters and the control button is selected, you get a run-time error 1004. I'd like to have a pop-up saying the spreadsheet is not currently filtered, or words to the like. Below is my code so far:

VBA Code:
Sub ClearFilters_Click() ' clear filters
ActiveSheet.Unprotect Password:="1234"
Sheets("CMLog").Rows("10:10000").EntireRow.Hidden = False
Sheets("CMLog").Columns("B:AC").EntireColumn.Hidden = False
Sheets("CMLog").ShowAllData
    Range("E4") = ("ALL")
    Range("H4") = ("ALL")
    Range("L4") = ("ALL")

ActiveSheet.Protect Password:="1234"

End Sub


Thank you,
Kat
 

Excel Facts

Excel Can Read to You
Customize Quick Access Toolbar. From All Commands, add Speak Cells or Speak Cells on Enter to QAT. Select cells. Press Speak Cells.
Hi,
try updating your code as follows & see if helps you

VBA Code:
With Worksheets("CMLog")
    If .FilterMode Then .ShowAllData Else MsgBox "spreadsheet is not currently filtered", 64, "Not Filtered"
End With

Dave
 
Upvote 0
Solution
Hi,
try updating your code as follows & see if helps you

VBA Code:
With Worksheets("CMLog")
    If .FilterMode Then .ShowAllData Else MsgBox "spreadsheet is not currently filtered", 64, "Not Filtered"
End With

Dave
Thank you Dave, that worked beautifully! I appreciate the help and this code is definitely simpler. Have a great day.
Kat
 
Upvote 0
welcome glad suggestion does what you want & appreciate feedback

Dave
 
Upvote 0

Forum statistics

Threads
1,213,506
Messages
6,114,024
Members
448,543
Latest member
MartinLarkin

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