ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Macro to Un Hide filtered rows (https://www.excelbanter.com/excel-programming/436662-macro-un-hide-filtered-rows.html)

JeffK

Macro to Un Hide filtered rows
 
I have this Macro

Sub Macro2()
Const csPWORD As String = "123"
ActiveWorkbook.Worksheets("broker").Unprotect Password:=csPWORD
ActiveSheet.ShowAllData
ActiveWorkbook.Worksheets("broker").Protect Password:=csPWORD
End Sub

I get a bug error if the sheet is already un filtered and the next step of
protecting the sheet again doesn't happen. How do I change this to search
first to see if the worksheet is filtered and if it is then proceed with the
rest of the Macro.

ker_01

Macro to Un Hide filtered rows
 
One option would be to ignore the error;

Sub Macro2()
Const csPWORD As String = "123"
ActiveWorkbook.Worksheets("broker").Unprotect Password:=csPWORD
On error resume next
ActiveSheet.ShowAllData
on error goto 0
ActiveWorkbook.Worksheets("broker").Protect Password:=csPWORD
End Sub

HTH,
Keith

"JeffK" wrote:

I have this Macro

Sub Macro2()
Const csPWORD As String = "123"
ActiveWorkbook.Worksheets("broker").Unprotect Password:=csPWORD
ActiveSheet.ShowAllData
ActiveWorkbook.Worksheets("broker").Protect Password:=csPWORD
End Sub

I get a bug error if the sheet is already un filtered and the next step of
protecting the sheet again doesn't happen. How do I change this to search
first to see if the worksheet is filtered and if it is then proceed with the
rest of the Macro.


JeffK

Macro to Un Hide filtered rows
 
Keith, worked like a charm,

Thanks

"ker_01" wrote:

One option would be to ignore the error;

Sub Macro2()
Const csPWORD As String = "123"
ActiveWorkbook.Worksheets("broker").Unprotect Password:=csPWORD
On error resume next
ActiveSheet.ShowAllData
on error goto 0
ActiveWorkbook.Worksheets("broker").Protect Password:=csPWORD
End Sub

HTH,
Keith

"JeffK" wrote:

I have this Macro

Sub Macro2()
Const csPWORD As String = "123"
ActiveWorkbook.Worksheets("broker").Unprotect Password:=csPWORD
ActiveSheet.ShowAllData
ActiveWorkbook.Worksheets("broker").Protect Password:=csPWORD
End Sub

I get a bug error if the sheet is already un filtered and the next step of
protecting the sheet again doesn't happen. How do I change this to search
first to see if the worksheet is filtered and if it is then proceed with the
rest of the Macro.


Dave Peterson

Macro to Un Hide filtered rows
 
Sub Macro2()
Const csPWORD As String = "123"

With activeworkbook.worksheets("broker")

.unprotect password:=cspword

'to remove the filter and the arrows
.AutoFilterMode = False

'or to just show all the data and keep the arrows
If .FilterMode Then
.ShowAllData
End If

.protect password:=cspword
End With
End Sub

JeffK wrote:

I have this Macro

Sub Macro2()
Const csPWORD As String = "123"
ActiveWorkbook.Worksheets("broker").Unprotect Password:=csPWORD
ActiveSheet.ShowAllData
ActiveWorkbook.Worksheets("broker").Protect Password:=csPWORD
End Sub

I get a bug error if the sheet is already un filtered and the next step of
protecting the sheet again doesn't happen. How do I change this to search
first to see if the worksheet is filtered and if it is then proceed with the
rest of the Macro.


--

Dave Peterson


All times are GMT +1. The time now is 07:29 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com