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

Workdays for a market open Mon, Wed, Friday?
Yes! Use "0101011" for the weekend argument in NETWORKDAYS.INTL or WORKDAY.INTL. The 7 digits start on Monday. 1 means it is a weekend.

dmt32

Well-known Member
Joined
Jul 3, 2012
Messages
7,912
Office Version
  1. 2021
  2. 2019
Platform
  1. Windows
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

KatKitKat

New Member
Joined
Apr 27, 2022
Messages
33
Office Version
  1. 365
Platform
  1. Windows
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

dmt32

Well-known Member
Joined
Jul 3, 2012
Messages
7,912
Office Version
  1. 2021
  2. 2019
Platform
  1. Windows
welcome glad suggestion does what you want & appreciate feedback

Dave
 
Upvote 0

Forum statistics

Threads
1,187,221
Messages
5,962,300
Members
438,600
Latest member
jagadeesan12

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
Top