+ Reply to Thread
Results 1 to 4 of 4

Run code only on selected sheets

  1. #1
    Registered User
    Join Date
    07-21-2010
    Location
    Bakersfield, CA
    MS-Off Ver
    Excel 2007
    Posts
    18

    Run code only on selected sheets

    I have a template that I need to add the ability to run code (print, format, etc..) only if the sheets are selected. Several sheets will be selected simultaneously, and I want the code to run only on those sheets.

    Most of the solutions I have seen require you to know the name of the sheets. In this template, sheet names are always changing. Also, the number of sheets changes. Sometimes we have a workbook with 3 sheets, sometimes with 100+.

    Thanks in advance for the help!
    Last edited by ericsastud; 02-01-2011 at 03:10 PM.

  2. #2
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,447

    Re: Run code only on selected sheets

    Not sure what you want to do exactly.

    The following code selects three sheets and does a Print Preview.

    Please Login or Register  to view this content.
    If the sheets were already selected, you could just run the PrintPreview.

    This code displays the sheet name for each selected sheet:

    Please Login or Register  to view this content.

    Something to try?

    Regards
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


  3. #3
    Registered User
    Join Date
    07-21-2010
    Location
    Bakersfield, CA
    MS-Off Ver
    Excel 2007
    Posts
    18

    Re: Run code only on selected sheets

    Thanks for the response. Sorry if I wasn't clear enough. I was actually thinking of something like this (except of course this doesn't work):

    Please Login or Register  to view this content.
    The problem lies with being able for my code to know which sheets have been selected.

  4. #4
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: Run code only on selected sheets

    Hi,

    How about

    Please Login or Register  to view this content.
    Rgds
    Richard Buttrey

    RIP - d. 06/10/2022

    If any of the responses have helped then please consider rating them by clicking the small star icon below the post.

+ 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