ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Code Procedure for multiple sheets (https://www.excelbanter.com/excel-programming/395818-code-procedure-multiple-sheets.html)

AMY Z.

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



George Nicholson

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





joel

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




All times are GMT +1. The time now is 11:58 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com