PC Review


Reply
Thread Tools Rate Thread

Code Procedure for multiple sheets

 
 
=?Utf-8?B?QU1ZIFou?=
Guest
Posts: n/a
 
      17th Aug 2007
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 With Quote
 
 
 
 
George Nicholson
Guest
Posts: n/a
 
      17th Aug 2007
*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." <(E-Mail Removed)> wrote in message
news:6D5744FD-54D6-4C57-901F-(E-Mail Removed)...
> 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 With Quote
 
=?Utf-8?B?Sm9lbA==?=
Guest
Posts: n/a
 
      17th Aug 2007
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 With Quote
 
=?Utf-8?B?QU1ZIFou?=
Guest
Posts: n/a
 
      18th Aug 2007
Thank you for taking time to answer my question, Joel and Mr. Richardson.

I tried to change my procedure with the recommendations, but VB didn't like
it.

This is the complete procedure I use now that works:

Sub HideColRowsProcedure()

Dim myCell As Range
Set myCell = Range("H2")

With Worksheets("Sheet2") 'HIDE ROWS
.Rows("28:280").EntireRow.Hidden = False
If myCell.Text = "APPLES" Then ' Hide rows if H2 in sheet1
says APPLES
.Rows("29:40").EntireRow.Hidden = True
.Rows("43:56").EntireRow.Hidden = True

End If
End With
End Sub

I changed back to standard sheet names to make it easier to understand.
If you are in Sheet1 and enter "APPLES" in cell H2. It hides the two rows
in Sheet2.

I would like the procedure to also do the same thing in Sheet3 at the same
time.

Maybe this can't be done. I'm just learning VB.
Amy
 
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
Trouble selecting multiple sheets using RDB code John Yab Microsoft Excel Programming 11 21st Dec 2009 03:44 AM
Code to Copy a Formula to Multiple Sheets Q Seanie Microsoft Excel Programming 2 5th Nov 2008 04:06 PM
Help on VBA Code to populate multiple sheets TLIUALL@gmail.com Microsoft Excel Misc 1 15th Jan 2008 04:40 AM
Modify code for multiple sheets-Help defining array =?Utf-8?B?VG9kZEVa?= Microsoft Excel Programming 6 19th Oct 2007 08:52 PM
change code to work over multiple sheets cda_cmd Microsoft Excel Programming 2 15th Feb 2006 01:05 AM


Features
 

Advertising
 

Newsgroups
 


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