PDA

View Full Version : Macro line for all worksheets



mogambo
12-22-2008, 12:46 AM
Hello

My question:

How can I make this macro run on all worksheets excluding only 2 worksheets in my workbook ?



Sub Hide_Colors_Zeros()

Dim Rng As Range
Dim MyCell As Range
Dim c As Range

Set Rng = Range("B2:B1000")

For Each MyCell In Rng

If MyCell.Font.ColorIndex = 3 Then
MyCell.EntireRow.Hidden = True
End If

Next MyCell
For Each c In Range("S2:S1000")
If c.Value = "Hide" Then
c.EntireRow.Hidden = True
End If
Next

End Sub


Could someone please help me to solve this ?

Simon Lloyd
12-22-2008, 01:23 AM
Like this!Dim ws As Worksheet
For each ws in sheets
if ws.name="Sheet1" or ws.name="Sheet2" then
else
YOUR CODE HERE
end if
Next ws

mogambo
12-22-2008, 02:14 AM
I have over 50 worksheets. I do not want to run the above macro only on 2 of them. I want the macro to run on all of the 48 worksheets.

Do I have to mention the names of these 48 worksheets manually in your code ? It will be really tedious to do that. Do you have some other alternative please ?

Benzadeus
12-22-2008, 05:15 AM
Using the same macro:
Dim ws As Worksheet
For Each ws In Sheets
If ws.Name = "Sheet1" Or ws.Name = "Sheet2" Then
'CODE THAT WILL RUN ON TWO SHEETS ABOVE
Else
'CODE THAT WILL RUN ON THE OTHERS 48 SHEETS
End If
Next ws

mdmackillop
12-22-2008, 06:02 AM
I have over 50 worksheets. I do not want to run the above macro only on 2 of them. I want the macro to run on all of the 48 worksheets.

Do I have to mention the names of these 48 worksheets manually in your code ? It will be really tedious to do that. Do you have some other alternative please ?
Did you test the solution before you replied? I guess not!

mogambo
12-23-2008, 04:56 AM
No, I have not tried it yet. But I will be try it soon because right now I am not having a chance to try it out. I will post my feedback once I do it on my computer.

Thank you all for all help.

Simon Lloyd
12-23-2008, 07:54 AM
No, I have not tried it yet. But I will be try it soon because right now I am not having a chance to try it out. I will post my feedback once I do it on my computer.

Thank you all for all help.Are you not using a computer right now to access this forum?

mogambo
12-30-2008, 07:44 AM
I was checking the reply to my post from a cyber cafe where MS-Office was not installed and so I said that in my post that I will post the feedback once I do it on my computer where MS-Office is installed.

I was out for holidays and returned just a couple of days back trying to solve another problem which I posted in another thread and I am getting quite offensive answer like if it is my "homework".

http://www.vbaexpress.com/forum/showthread.php?t=24443

Why do you people reply to the thread if you do not want to help concluding things at your will without realizing the facts ? I know that this is a free help forum but even so why do you want to conclude anything what comes to your mind without even trying to find out the reality ?

Anyways, I know that I was polite in all my threads and I have not offended any rules of this forum. Its a wide world with a lot of different people and I do not blame you for it.

Thanks you for all your help in regards to this thread as well as all other threads. I think I will have to ask help in another forum.

lucas
12-30-2008, 05:19 PM
mogambo, here is what you said in that thread that was considered by at least me to be offensive:


It looks like no one including you knows the answer to the question and so a lame excuse. I am 40 years old for your information and I don't go to school anymore. Your aims are high on this forum but the help you give is too little and that too with PROOFING.

Its a pity I came here and requested help.


This was my response to your post:


You seem not to understand that the help here is voluntary and free. The least you could do when seeking free assistance is be civil.

Contrary to your opinion, many get good help here and are happy with the forum.

You can't come to a forum such as this and make demanding, demeaning remarks and expect people to rush to your assistance.

I then locked the thread and pm'ed you and requested that you contact me before taking any further action.......

Instead you have posted more disparaging remarks here and not once have you apologized to anyone for your behavior.


Banned

Simon Lloyd
12-31-2008, 04:42 AM
It seems he got under a few peoples skins in a very short space of time!