Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 7
Default referencing multiple worksheets in macro

So I kind of found the answer to my question in a post from a couple years
ago but am still confused so if anyone could help I'd appreciate it...I'm
trying to protect the sheet while still being able to use the subtotal
function. I have several worksheets I want to do this for and this is the
post from before with the code but I can't figure out where to put the names
of my worksheets ("01","02","03") and what I need to customize in the code
for my file. Any suggestions?

Option Explicit
Sub auto_open()
dim wks as worksheet
for each wks in thisworkbook.worksheets
with wks
.select 'see note below
.Protect Password:="hi", userinterfaceonly:=True
.EnableOutlining = True
.EnableAutoFilter = True
End With
application.goto thisworkbook.worksheets(1).range("a1"), scroll:=true
End Sub

Tom Ogilvy has reported that sometimes protecting sheets will work better if
it's selected first.

Change the application.goto line to where you want to goto <vbg when the
code
ends.
  #2   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 2,203
Default referencing multiple worksheets in macro

First, your code appears to be missing a "Next" to go with the "For each
wks..." statement.

But, in that code, wks represents each worksheet in the workbook in turn.
It doesn't need to know the sheet's name to do what it is doing.

But if you need to determine a worksheet's name within that loop, you can
use something like
If wks.Name = "01" Then
'do something special with sheet named 01
End If

What the code is doing is this, for each and every sheet in the workbook:

..Select ' selects/activates a sheet
..Protect ... ' that turns the protection on for the selected sheet
..EnableOutlining = True ' does that for the selected sheet
..EnableAutoFilter = True ' does that for the selected sheet

Once it has worked through all of the worksheets, it is going to jump back
to the first sheet in the workbook and select cell A1 on it.


The code with the missing Next statement added

Option Explicit
Sub auto_open()
dim wks as worksheet
for each wks in thisworkbook.worksheets
with wks
.select 'see note below
.Protect Password:="hi", userinterfaceonly:=True
.EnableOutlining = True
.EnableAutoFilter = True
End With
Next
application.goto thisworkbook.worksheets(1).range("a1"), scroll:=true
End Sub


"Michelle Thompson" wrote:

So I kind of found the answer to my question in a post from a couple years
ago but am still confused so if anyone could help I'd appreciate it...I'm
trying to protect the sheet while still being able to use the subtotal
function. I have several worksheets I want to do this for and this is the
post from before with the code but I can't figure out where to put the names
of my worksheets ("01","02","03") and what I need to customize in the code
for my file. Any suggestions?

Option Explicit
Sub auto_open()
dim wks as worksheet
for each wks in thisworkbook.worksheets
with wks
.select 'see note below
.Protect Password:="hi", userinterfaceonly:=True
.EnableOutlining = True
.EnableAutoFilter = True
End With
application.goto thisworkbook.worksheets(1).range("a1"), scroll:=true
End Sub

Tom Ogilvy has reported that sometimes protecting sheets will work better if
it's selected first.

Change the application.goto line to where you want to goto <vbg when the
code
ends.

  #3   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 7
Default referencing multiple worksheets in macro

thank you very much for explaining the code and fixing it for me, it worked
great!

"JLatham" wrote:

First, your code appears to be missing a "Next" to go with the "For each
wks..." statement.

But, in that code, wks represents each worksheet in the workbook in turn.
It doesn't need to know the sheet's name to do what it is doing.

But if you need to determine a worksheet's name within that loop, you can
use something like
If wks.Name = "01" Then
'do something special with sheet named 01
End If

What the code is doing is this, for each and every sheet in the workbook:

.Select ' selects/activates a sheet
.Protect ... ' that turns the protection on for the selected sheet
.EnableOutlining = True ' does that for the selected sheet
.EnableAutoFilter = True ' does that for the selected sheet

Once it has worked through all of the worksheets, it is going to jump back
to the first sheet in the workbook and select cell A1 on it.


The code with the missing Next statement added

Option Explicit
Sub auto_open()
dim wks as worksheet
for each wks in thisworkbook.worksheets
with wks
.select 'see note below
.Protect Password:="hi", userinterfaceonly:=True
.EnableOutlining = True
.EnableAutoFilter = True
End With
Next
application.goto thisworkbook.worksheets(1).range("a1"), scroll:=true
End Sub


"Michelle Thompson" wrote:

So I kind of found the answer to my question in a post from a couple years
ago but am still confused so if anyone could help I'd appreciate it...I'm
trying to protect the sheet while still being able to use the subtotal
function. I have several worksheets I want to do this for and this is the
post from before with the code but I can't figure out where to put the names
of my worksheets ("01","02","03") and what I need to customize in the code
for my file. Any suggestions?

Option Explicit
Sub auto_open()
dim wks as worksheet
for each wks in thisworkbook.worksheets
with wks
.select 'see note below
.Protect Password:="hi", userinterfaceonly:=True
.EnableOutlining = True
.EnableAutoFilter = True
End With
application.goto thisworkbook.worksheets(1).range("a1"), scroll:=true
End Sub

Tom Ogilvy has reported that sometimes protecting sheets will work better if
it's selected first.

Change the application.goto line to where you want to goto <vbg when the
code
ends.

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
Cell Referencing between multiple worksheets Nelson B. Excel Discussion (Misc queries) 4 July 24th 09 08:55 AM
Referencing cells in multiple worksheets Andrew W Excel Discussion (Misc queries) 3 August 6th 08 02:23 PM
Excel 2003 Referencing multiple worksheets EdGarrett Excel Discussion (Misc queries) 3 January 31st 08 02:48 PM
Macro referencing multiple worksheets JULZ Excel Discussion (Misc queries) 1 October 9th 06 07:46 PM
Summary worksheet referencing multiple worksheets Jon Excel Worksheet Functions 1 January 27th 05 01:12 AM


All times are GMT +1. The time now is 03:56 AM.

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"