Consulting

Results 1 to 10 of 10

Thread: Macro line for all worksheets

  1. #1
    Banned VBAX Regular
    Joined
    Nov 2008
    Posts
    20
    Location

    Macro line for all worksheets

    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 ?

  2. #2
    Moderator VBAX Guru Simon Lloyd's Avatar
    Joined
    Sep 2005
    Location
    UK
    Posts
    3,003
    Location
    Like this![vba]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[/vba]
    Regards,
    Simon
    Please read this before cross posting!
    In the unlikely event you didn't get your answer here try Microsoft Office Discussion @ The Code Cage
    If I have seen further it is by standing on the shoulders of giants.
    Isaac Newton, Letter to Robert Hooke, February 5, 1675 English mathematician & physicist (1642 - 1727)

  3. #3
    Banned VBAX Regular
    Joined
    Nov 2008
    Posts
    20
    Location
    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 ?

  4. #4
    VBAX Tutor Benzadeus's Avatar
    Joined
    Dec 2008
    Location
    Belo Horizonte, Brazil
    Posts
    271
    Location
    Using the same macro:
    [VBA]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
    [/VBA]

  5. #5
    Administrator
    VP-Knowledge Base
    VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    Quote Originally Posted by mogambo
    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!
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  6. #6
    Banned VBAX Regular
    Joined
    Nov 2008
    Posts
    20
    Location
    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.

  7. #7
    Moderator VBAX Guru Simon Lloyd's Avatar
    Joined
    Sep 2005
    Location
    UK
    Posts
    3,003
    Location
    Quote Originally Posted by mogambo
    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?
    Regards,
    Simon
    Please read this before cross posting!
    In the unlikely event you didn't get your answer here try Microsoft Office Discussion @ The Code Cage
    If I have seen further it is by standing on the shoulders of giants.
    Isaac Newton, Letter to Robert Hooke, February 5, 1675 English mathematician & physicist (1642 - 1727)

  8. #8
    Banned VBAX Regular
    Joined
    Nov 2008
    Posts
    20
    Location
    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.

  9. #9
    Moderator VBAX Wizard lucas's Avatar
    Joined
    Jun 2004
    Location
    Tulsa, Oklahoma
    Posts
    7,323
    Location
    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
    Steve
    "Nearly all men can stand adversity, but if you want to test a man's character, give him power."
    -Abraham Lincoln

  10. #10
    Moderator VBAX Guru Simon Lloyd's Avatar
    Joined
    Sep 2005
    Location
    UK
    Posts
    3,003
    Location
    It seems he got under a few peoples skins in a very short space of time!
    Regards,
    Simon
    Please read this before cross posting!
    In the unlikely event you didn't get your answer here try Microsoft Office Discussion @ The Code Cage
    If I have seen further it is by standing on the shoulders of giants.
    Isaac Newton, Letter to Robert Hooke, February 5, 1675 English mathematician & physicist (1642 - 1727)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •