Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 31
Default Code Procedure for multiple sheets

Hi,
I have a procedure that formats Worksheet1 when something happens in a
certain cell. Worksheet1 is titled: APPLES. The procedure I have for this
works great.

Working part of the procedure I have now looks like this:

With Worksheets("APPLES")
Hide rows, change font color etc.

I would now also like to have the same thing happen in Worksheet2.
Worksheet2 is called ORANGES. Something like: With Worksheets("APPLES &
ORANGES")....

Is is possible to have mutiple worksheets follow the same procedure?

Thank you for your time,
Amy


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 149
Default Code Procedure for multiple sheets

*Method one
Dim varSheets As Variant
Dim i as Integer

varSheets = Array("Apples", "Oranges")

For i = lbound(varsheets) to ubound(varsheets)
With Worksheets(varSheets(i))
'..........your code
End With
Next i

*Method two
Dim wks as Worksheet

For Each wks in Worksheets
Select Case wks.Name
Case "Apples", "Oranges"
With wks
'.........your code
End With
Case Else
'Do nothing
End Select
Next wks

HTH,

"AMY Z." wrote in message
...
Hi,
I have a procedure that formats Worksheet1 when something happens in a
certain cell. Worksheet1 is titled: APPLES. The procedure I have for
this
works great.

Working part of the procedure I have now looks like this:

With Worksheets("APPLES")
Hide rows, change font color etc.

I would now also like to have the same thing happen in Worksheet2.
Worksheet2 is called ORANGES. Something like: With Worksheets("APPLES &
ORANGES")....

Is is possible to have mutiple worksheets follow the same procedure?

Thank you for your time,
Amy




  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9,101
Default Code Procedure for multiple sheets

Here is one method

for each ws in worksheets
if (ws.name = "APPLES") OR (ws.name = "ORANGES") then
with worksheets(ws.name)
'put your code here

end with

end if

next ws

"AMY Z." wrote:

Hi,
I have a procedure that formats Worksheet1 when something happens in a
certain cell. Worksheet1 is titled: APPLES. The procedure I have for this
works great.

Working part of the procedure I have now looks like this:

With Worksheets("APPLES")
Hide rows, change font color etc.

I would now also like to have the same thing happen in Worksheet2.
Worksheet2 is called ORANGES. Something like: With Worksheets("APPLES &
ORANGES")....

Is is possible to have mutiple worksheets follow the same procedure?

Thank you for your time,
Amy


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
A macro code to print multiple sheets in different w.books Gladiator Excel Discussion (Misc queries) 3 February 22nd 10 07:49 PM
Help on VBA Code to populate multiple sheets [email protected] Excel Discussion (Misc queries) 1 January 15th 08 04:40 AM
change code to work over multiple sheets cda_cmd Excel Programming 2 February 15th 06 01:05 AM
Rename Multiple Sheets - Help with Mr Dave Peterson's Code [email protected] Excel Programming 2 January 4th 06 09:16 AM
Sort Sheets Procedure Sandman[_2_] Excel Programming 5 April 28th 04 04:37 PM


All times are GMT +1. The time now is 06:50 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"