Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
DJH DJH is offline
external usenet poster
 
Posts: 14
Default References to multiple sheets

What is the correct syntax to process through all sheets in a workbook when
you do not know how many sheets there will be? I want to have a macro run to
delete certain rows in each sheet, but the number of sheets will vary.

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,119
Default References to multiple sheets

Sub TraverseSheets
dim wks as worksheet

for each wks in worksheets
msgbox wks.name
wks.range("A5:A10").select
next wks
end sub

--
HTH...

Jim Thomlinson


"djh" wrote:

What is the correct syntax to process through all sheets in a workbook when
you do not know how many sheets there will be? I want to have a macro run to
delete certain rows in each sheet, but the number of sheets will vary.

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default References to multiple sheets

Dim sh as worksheet
for each sh in ActiveWorkbook.Worksheets
sh.Range("5:8").Delete
Next

another way

Sub SS()
Set sh = ActiveSheet
ActiveWorkbook.Worksheets.Select
Range("5:8").Select
Selection.Delete
sh.Select
End Sub


--
Regards,
Tom Ogilvy


"djh" wrote in message
...
What is the correct syntax to process through all sheets in a workbook

when
you do not know how many sheets there will be? I want to have a macro run

to
delete certain rows in each sheet, but the number of sheets will vary.



  #4   Report Post  
Posted to microsoft.public.excel.programming
DJH DJH is offline
external usenet poster
 
Posts: 14
Default References to multiple sheets

Thanks, your first solution worked great.

"Tom Ogilvy" wrote:

Dim sh as worksheet
for each sh in ActiveWorkbook.Worksheets
sh.Range("5:8").Delete
Next

another way

Sub SS()
Set sh = ActiveSheet
ActiveWorkbook.Worksheets.Select
Range("5:8").Select
Selection.Delete
sh.Select
End Sub


--
Regards,
Tom Ogilvy


"djh" wrote in message
...
What is the correct syntax to process through all sheets in a workbook

when
you do not know how many sheets there will be? I want to have a macro run

to
delete certain rows in each sheet, but the number of sheets will vary.




  #5   Report Post  
Posted to microsoft.public.excel.programming
DJH DJH is offline
external usenet poster
 
Posts: 14
Default References to multiple sheets

I ran into a probelm with run-time error 1004. Select method of range failed.
I ended up using code from Tom Ogilvy's posting.
Thanks anyway.

"Jim Thomlinson" wrote:

Sub TraverseSheets
dim wks as worksheet

for each wks in worksheets
msgbox wks.name
wks.range("A5:A10").select
next wks
end sub

--
HTH...

Jim Thomlinson


"djh" wrote:

What is the correct syntax to process through all sheets in a workbook when
you do not know how many sheets there will be? I want to have a macro run to
delete certain rows in each sheet, but the number of sheets will vary.



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default References to multiple sheets

In that code, You have to select the sheet before you select the range on
the sheet.


Sub TraverseSheets
dim wks as worksheet

for each wks in worksheets
wks.Select
msgbox wks.name
wks.range("A5:A10").select
next wks
end sub

--
Regards,
Tom Ogilvy


"djh" wrote in message
...
I ran into a probelm with run-time error 1004. Select method of range

failed.
I ended up using code from Tom Ogilvy's posting.
Thanks anyway.

"Jim Thomlinson" wrote:

Sub TraverseSheets
dim wks as worksheet

for each wks in worksheets
msgbox wks.name
wks.range("A5:A10").select
next wks
end sub

--
HTH...

Jim Thomlinson


"djh" wrote:

What is the correct syntax to process through all sheets in a workbook

when
you do not know how many sheets there will be? I want to have a macro

run to
delete certain rows in each sheet, but the number of sheets will vary.



  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,119
Default References to multiple sheets

Thanks for clearing that up Tom. I originally had a clearcontents in there
but changed it at the last second for fear that the OP might run it against
some critical data... Didn't think it through.
--
HTH...

Jim Thomlinson


"Tom Ogilvy" wrote:

In that code, You have to select the sheet before you select the range on
the sheet.


Sub TraverseSheets
dim wks as worksheet

for each wks in worksheets
wks.Select
msgbox wks.name
wks.range("A5:A10").select
next wks
end sub

--
Regards,
Tom Ogilvy


"djh" wrote in message
...
I ran into a probelm with run-time error 1004. Select method of range

failed.
I ended up using code from Tom Ogilvy's posting.
Thanks anyway.

"Jim Thomlinson" wrote:

Sub TraverseSheets
dim wks as worksheet

for each wks in worksheets
msgbox wks.name
wks.range("A5:A10").select
next wks
end sub

--
HTH...

Jim Thomlinson


"djh" wrote:

What is the correct syntax to process through all sheets in a workbook

when
you do not know how many sheets there will be? I want to have a macro

run to
delete certain rows in each sheet, but the number of sheets will vary.




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
coounting references between sheets Dez Excel Worksheet Functions 2 April 10th 08 02:56 PM
Transposing Multiple Cell References to Multiple Values (NOT total LinLin Excel Discussion (Misc queries) 7 November 11th 07 10:57 PM
Relative References to other sheets stevevalwa Excel Discussion (Misc queries) 1 December 30th 06 06:46 PM
Excel references to other sheets kmhog Excel Worksheet Functions 2 February 27th 06 11:23 PM
Linking References from Multiple Sheets to One Summary Sheet Kim Setting up and Configuration of Excel 3 May 5th 05 04:56 PM


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

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

About Us

"It's about Microsoft Excel"