+ Reply to Thread
Results 1 to 6 of 6

Apply Macro to specific worksheets in workbook

  1. #1
    Forum Contributor
    Join Date
    07-29-2013
    Location
    Oshawa
    MS-Off Ver
    Excel 2010
    Posts
    660

    Apply Macro to specific worksheets in workbook

    Hi everyone,

    I have a different question regarding this macro in another post, so I figured I'd put in a separate post for it. I have the following macro:

    Please Login or Register  to view this content.
    So right now the macro is run in every single worksheet in the workbook. Unfortunately, it appears the TRIM function erases formulas in cells. I want this macro to apply only to certain worksheets. Say the worksheets i want the macro to run on are named A1-A100. How could I apply this?

    Thanks!!

  2. #2
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: Apply Macro to specific worksheets in workbook

    Maybe:

    Please Login or Register  to view this content.

  3. #3
    Forum Contributor
    Join Date
    07-29-2013
    Location
    Oshawa
    MS-Off Ver
    Excel 2010
    Posts
    660

    Re: Apply Macro to specific worksheets in workbook

    Hi John,

    Thanks. So Sheets(Range("A" & i).Value).Activate indicates the macro should work on any worksheets that start with an "A"?

    So my worksheets are named like this PA (1) PA (2), etc. Does that mean it should be:

    For i = 1 To 100
    Sheets(Range("PA (" & i).Value).Activate

  4. #4
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: Apply Macro to specific worksheets in workbook

    I may have been mistaken. I assumed when you said "Say the worksheets i want the macro to run on are named A1-A100" you were talking about a range in Column A. This macro gets the values from A1:A100 in Column A?

  5. #5
    Forum Guru HaHoBe's Avatar
    Join Date
    02-19-2005
    Location
    Hamburg, Germany
    MS-Off Ver
    work: 2016 on Win10 (notebook), private: 2019 on Win10 (desktop), 2019 on Win11 (notebook)
    Posts
    8,198

    Re: Apply Macro to specific worksheets in workbook

    Hi, Groovicles,

    maybe like this:
    Please Login or Register  to view this content.
    Ciao,
    Holger
    Use Code-Tags for showing your code: [code] Your Code here [/code]
    Please mark your question Solved if there has been offered a solution that works fine for you

  6. #6
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: Apply Macro to specific worksheets in workbook

    Modified:

    Please Login or Register  to view this content.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Trying to apply vba coding to two worksheets in same workbook
    By Kaz09 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 01-24-2014, 07:01 AM
  2. [SOLVED] Macro to copy specific worksheets into a new workbook
    By Groovicles in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 11-15-2013, 10:28 AM
  3. [SOLVED] Apply Macro to all the Worksheets in Workbook
    By Floydlevedale in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 04-16-2013, 05:54 AM
  4. create & Apply a macro to all worksheets in a workbook
    By sleetwx in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 11-13-2012, 09:42 AM
  5. apply macro to all worksheets in the workbook
    By jbyrne in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 03-15-2010, 09:40 AM

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