+ Reply to Thread
Results 1 to 4 of 4

Doing a macro in every worksheet except 2

  1. #1
    Registered User
    Join Date
    10-07-2005
    Posts
    48

    Doing a macro in every worksheet except 2

    Hi all,

    I have potentailly unlimited worksheets to my database which can be added at will, but all have a column which is identical except 2.

    I need some code that will look at all worksheets except those two and carry out my macro.

    I thought: For Each Sheet In ActiveWorkbook.Sheets would work but i cant seem to use it for this.

    Any help would be appreciated.

  2. #2
    Bob Phillips
    Guest

    Re: Doing a macro in every worksheet except 2

    You can, but you have to outsort the exceptions, something like

    For Each sh In ActiveWorkbook.Sheets
    If sh.Name <> "name1" Ad sh.Name <> "Name2" Then
    'do your stuff
    End If
    Next sh

    --
    HTH

    Bob Phillips

    (remove nothere from email address if mailing direct)

    "kanuvas" <[email protected]> wrote in
    message news:[email protected]...
    >
    > Hi all,
    >
    > I have potentailly unlimited worksheets to my database which can be
    > added at will, but all have a column which is identical except 2.
    >
    > I need some code that will look at all worksheets except those two and
    > carry out my macro.
    >
    > I thought: For Each Sheet In ActiveWorkbook.Sheets would work but i
    > cant seem to use it for this.
    >
    > Any help would be appreciated.
    >
    >
    > --
    > kanuvas
    > ------------------------------------------------------------------------
    > kanuvas's Profile:

    http://www.excelforum.com/member.php...o&userid=27911
    > View this thread: http://www.excelforum.com/showthread...hreadid=477084
    >




  3. #3
    Norman Jones
    Guest

    Re: Doing a macro in every worksheet except 2

    Hi Kanuvas,

    Try something like:
    '==================>>
    Sub Tester()

    Dim WS As Worksheet

    For Each WS In ActiveWorkbook.Worksheets
    If WS.Name <> "Sheet3" And WS.Name <> "Sheet4" Then
    'run your code, e.g.:
    MsgBox WS.Name
    End If
    Next WS

    End Sub
    '<<==================

    Change Sheet3 and sheet 4 to the names of the sheets of interest.

    ---
    Regards,
    Norman



    "kanuvas" <[email protected]> wrote in
    message news:[email protected]...
    >
    > Hi all,
    >
    > I have potentailly unlimited worksheets to my database which can be
    > added at will, but all have a column which is identical except 2.
    >
    > I need some code that will look at all worksheets except those two and
    > carry out my macro.
    >
    > I thought: For Each Sheet In ActiveWorkbook.Sheets would work but i
    > cant seem to use it for this.
    >
    > Any help would be appreciated.
    >
    >
    > --
    > kanuvas
    > ------------------------------------------------------------------------
    > kanuvas's Profile:
    > http://www.excelforum.com/member.php...o&userid=27911
    > View this thread: http://www.excelforum.com/showthread...hreadid=477084
    >




  4. #4
    Registered User
    Join Date
    10-07-2005
    Posts
    48
    Thanks a lot guys both worked wonders.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1