Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Autofilter protected sheet


Hello, I have used the code below to unlock the autofilter on
protected sheet in excel. I'm not very good at VBA, so could someon
tell me how to change it so that it works for all of the sheets in th
workbook instead of just 2005?

Thanks

Private Sub Workbook_Open()
'check for filter, turn on if none exists
With Worksheets("2005")
If Not .AutoFilterMode Then
.Range("A4:C4").AutoFilter
End If
.EnableAutoFilter = True
.Protect Password:="password", _
Contents:=True, UserInterfaceOnly:=True
End With
End Su

--
veci
-----------------------------------------------------------------------
vecia's Profile: http://www.excelforum.com/member.php...nfo&userid=211
View this thread: http://www.excelforum.com/showthread.php?threadid=46640

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Autofilter protected sheet


Good evening vecia

Only two new lines are needed, and we can get rid of one.

Sub Workbook_Open()
'check for filter, turn on if none exists
For Each ws In ActiveWorkbook.Worksheets
With ws
If Not .AutoFilterMode Then
.Range("A4:C4").AutoFilter
End If
.EnableAutoFilter = True
.Protect Password:="password", _
Contents:=True, UserInterfaceOnly:=True
End With
Next ws
End Sub

You no longer need to specify the spreadsheet, because they will all b
done, so that line has gone, but replaced by a For ... Next loop whic
will perform the action on each sheet in turn.

HTH

Dominic

--
dominic
-----------------------------------------------------------------------
dominicb's Profile: http://www.excelforum.com/member.php...fo&userid=1893
View this thread: http://www.excelforum.com/showthread.php?threadid=46640

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,718
Default Autofilter protected sheet

This this:

Private Sub Workbook_Open()
Dim WS As Worksheet
For Each WS In ThisWorkbook.Worksheets
With WS
If Not .AutoFilterMode Then .Range("A4:C4").AutoFilter
.EnableAutoFilter = True
.Protect Password:="password", _
Contents:=True, UserInterfaceOnly:=True
End With
Next
End Sub


--
Jim
"vecia" wrote in
message ...

Hello, I have used the code below to unlock the autofilter on a
protected sheet in excel. I'm not very good at VBA, so could someone
tell me how to change it so that it works for all of the sheets in the
workbook instead of just 2005?

Thanks

Private Sub Workbook_Open()
'check for filter, turn on if none exists
With Worksheets("2005")
If Not .AutoFilterMode Then
Range("A4:C4").AutoFilter
End If
EnableAutoFilter = True
Protect Password:="password", _
Contents:=True, UserInterfaceOnly:=True
End With
End Sub


--
vecia
------------------------------------------------------------------------
vecia's Profile:
http://www.excelforum.com/member.php...fo&userid=2117
View this thread: http://www.excelforum.com/showthread...hreadid=466407



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,092
Default Autofilter protected sheet

Private Sub Workbook_Open()
Dim i As Long

For i = 1 To Worksheets.Count
'check for filter, turn on if none exists
If Worksheets(i).AutoFilterMode Then 'that is an i, not 1
GoTo 1
Else
Worksheets(i).Unprotect Password:="password"
Worksheets(i).Range("A4:C4").AutoFilter
End If
Worksheets(i).Protect Password:="password"
1:
Next i
End Sub

Mike F

"vecia" wrote in
message ...

Hello, I have used the code below to unlock the autofilter on a
protected sheet in excel. I'm not very good at VBA, so could someone
tell me how to change it so that it works for all of the sheets in the
workbook instead of just 2005?

Thanks

Private Sub Workbook_Open()
'check for filter, turn on if none exists
With Worksheets("2005")
If Not .AutoFilterMode Then
Range("A4:C4").AutoFilter
End If
EnableAutoFilter = True
Protect Password:="password", _
Contents:=True, UserInterfaceOnly:=True
End With
End Sub


--
vecia
------------------------------------------------------------------------
vecia's Profile:
http://www.excelforum.com/member.php...fo&userid=2117
View this thread: http://www.excelforum.com/showthread...hreadid=466407



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Autofilter protected sheet


Thanks everyone, these all do the job :cool

--
veci
-----------------------------------------------------------------------
vecia's Profile: http://www.excelforum.com/member.php...nfo&userid=211
View this thread: http://www.excelforum.com/showthread.php?threadid=46640

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Autofilter not working on protected sheet. parahumanoid[_2_] Excel Discussion (Misc queries) 1 November 1st 09 05:52 PM
Use autofilter with macro in a protected sheet Minos Excel Discussion (Misc queries) 1 August 4th 09 03:44 PM
Autofilter in protected sheet Javier Excel Worksheet Functions 5 March 24th 08 05:56 PM
Applying autofilter to protected sheet Brian Ferris Excel Discussion (Misc queries) 2 November 18th 05 04:28 PM
AutoFilter on a Protected sheet Olle[_2_] Excel Programming 1 June 15th 04 08:12 AM


All times are GMT +1. The time now is 10:12 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"