+ Reply to Thread
Results 1 to 6 of 6

Running macro on certain worksheets

  1. #1
    Registered User
    Join Date
    06-21-2009
    Location
    London, England
    MS-Off Ver
    Excel 2003
    Posts
    5

    Running macro on certain worksheets

    Hi all,

    I'm looking for a way to prevent a macro from being run on certain worksheets. In my workbook, there different types of sheets that I have made, for example Buying, Selling, etc...

    Say I want to have restrict a macro to run only on the Buying worksheets, is there a way to do this in code. Ideally, I want code it in such a way that it is transparent to the user, for example a CustomProperty or a variable within the code for a sheet that I can look up.


    Many thanks in advance.

    Best regards,
    Chun Te

  2. #2
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: Running macro on certain worksheets

    Hello Chunte,

    Welcome to the Forum!

    There a couple of ways to do this. It would really help to see your code. We could then tell you the best method to use. Posting your workbook would be best.
    Sincerely,
    Leith Ross

    Remember To Do the Following....

    1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.
    2. Thank those who have helped you by clicking the Star below the post.
    3. Please mark your post [SOLVED] if it has been answered satisfactorily.


    Old Scottish Proverb...
    Luathaid gu deanamh maille! (Rushing causes delays!)

  3. #3
    Registered User
    Join Date
    06-21-2009
    Location
    London, England
    MS-Off Ver
    Excel 2003
    Posts
    5

    Re: Running macro on certain worksheets

    Thanks for the quick response!

    For the piece of functionality that I'm thinking about, I've yet to make any code yet and still in the planning phase, so I don't think it is worth sharing the code.

    Essentially, there will be a macro that aggregates data from multiple sheets and places them into a new sheet. Which sheets are aggregated is determined by the User. I intend to have a TextBox where the User can list the sheetnames they want. I hope to then validate the list based on their types (e.g. 'Buying', 'Selling') as the macro would only work on certain type of sheets/templates.

    I could have a cell in the worksheet, e.g. A1, fixed with the value 'Buying' but I hope to not rely on that as the User might want to change the value of that cell. Hence, ideally I'd like to be able to code it into the sheet.

    Many many thanks....

    Chun Te
    Last edited by chunte; 06-21-2009 at 02:05 PM.

  4. #4
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: Running macro on certain worksheets

    Hello Chunte,

    The easiest method is to have the macro check the ActiveSheet's name. If it is not the sheet you want then exit the macro. Use this as the first line in the macro.
    Please Login or Register  to view this content.

  5. #5
    Registered User
    Join Date
    06-21-2009
    Location
    London, England
    MS-Off Ver
    Excel 2003
    Posts
    5

    Re: Running macro on certain worksheets

    Hi Leith,

    Hmm... That's right, but wouldn't that would work only if the name of the sheet is 'Buying'. The sheets would have different names to correspond to a different person and none of the sheets have the word 'Buying' in them.

    Best regards,
    Chun Te

  6. #6
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: Running macro on certain worksheets

    I think you are working backwards. Al data is best stored on one sheet, with a field for the names.

    Then yo can use PivotTables to work with the data
    Hope that helps.

    RoyUK
    --------
    For Excel Tips & Solutions, free examples and tutorials why not check out my web site

    Free DataBaseForm example

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Tags for this Thread

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