PC Review


Reply
Thread Tools Rate Thread

Code for multiple worksheets

 
 
Paul S
Guest
Posts: n/a
 
      17th Jun 2008

I am using excel 2000

How can I make the following code, saved in the This Workbook modul
available to

either all worksheets in the workbook

or specifically an additional worksheet called "Commission Achievement
as well as the "Missing Data" worksheetin my workbook

The code allows filterring on protected sheets

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


Thanks

Pau


--
Paul S
 
Reply With Quote
 
 
 
 
Dave Peterson
Guest
Posts: n/a
 
      17th Jun 2008
One way:

Option Explicit
Private Sub Workbook_Open()

Dim iCtr As Long
Dim WKSNames As Variant

WKSNames = Array("Missing data", _
"Commission Achievement")

For iCtr = LBound(WKSNames) To UBound(WKSNames)
With Me.Worksheets(WKSNames(iCtr))
If Not .AutoFilterMode Then
.Range("A3").AutoFilter
End If
.EnableAutoFilter = True
.Protect Contents:=True, UserInterfaceOnly:=True
End With
Next iCtr
End Sub

If you really wanted all the worksheets in that workbook:

Option Explicit
Private Sub Workbook_Open()

Dim wks As Worksheet

For Each wks In Me.Worksheets
With wks
If Not .AutoFilterMode Then
.Range("A3").AutoFilter
End If
.EnableAutoFilter = True
.Protect Contents:=True, UserInterfaceOnly:=True
End With
Next wks
End Sub

Paul S wrote:
>
> I am using excel 2000
>
> How can I make the following code, saved in the This Workbook module
> available to
>
> either all worksheets in the workbook
>
> or specifically an additional worksheet called "Commission Achievement"
> as well as the "Missing Data" worksheetin my workbook
>
> The code allows filterring on protected sheets
>
> Private Sub Workbook_Open()
> 'check for filter, turn on if none exists
> With Worksheets("Missing Data")
> If Not .AutoFilterMode Then
> Range("A3").AutoFilter
> End If
> EnableAutoFilter = True
> Protect _
> Contents:=True, UserInterfaceOnly:=True
> End With
> End Sub
>
> Thanks
>
> Paul
>
> --
> Paul S


--

Dave Peterson
 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Repeat code for multiple worksheets Mike Microsoft Excel Programming 2 23rd Apr 2009 08:17 PM
Delete Blank Rows Code - Multiple Worksheets - Multiple Documents =?Utf-8?B?QmVuUw==?= Microsoft Excel Misc 3 29th Jun 2007 12:20 AM
Need help on code - Macro on multiple worksheets =?Utf-8?B?SkBZ?= Microsoft Excel Misc 2 2nd Feb 2007 08:05 PM
Need to apply VBA code to multiple Worksheets parteegolfer Microsoft Excel Programming 2 12th Mar 2006 08:43 PM
Add VBA code to multiple WorkSheets =?Utf-8?B?QWw=?= Microsoft Excel Programming 0 24th May 2005 04:40 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 01:15 AM.