+ Reply to Thread
Results 1 to 5 of 5

vba code to apply a macro to a specific tab

  1. #1
    Registered User
    Join Date
    01-04-2012
    Location
    London
    MS-Off Ver
    Excel 2010
    Posts
    15

    vba code to apply a macro to a specific tab

    hi, i'm trying to find a way to prefix a macro i have so that when it is run it will only apply to a certain tab within a worksheet. currently, when run it will apply to the current tab i am in when i run it..

  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: vba code to apply a macro to a specific tab

    Something like:

    Please Login or Register  to view this content.

    Regards, TMS
    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
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,166

    Re: vba code to apply a macro to a specific tab

    You need to specify the tab name....for e.g.
    Please Login or Register  to view this content.
    considering that File is the workbook and Test is the sheet.
    If I have helped, Don't forget to add to my reputation (click on the star below the post)
    Don't forget to mark threads as "Solved" (Thread Tools->Mark thread as Solved)
    Use code tags when posting your VBA code: [code] Your code here [/code]

  4. #4
    Registered User
    Join Date
    01-04-2012
    Location
    London
    MS-Off Ver
    Excel 2010
    Posts
    15

    Re: vba code to apply a macro to a specific tab

    Thanks for the response. The answer is not quite what I was after though. The code you've provided means the macro will only run if i'm in a specific tab - which you have called "test sheet". I want the macro to run from any tab - but for the code to only apply to a specific tab. So I could be in Tab A or B but when I run the macro it ignores where I am and applies the code only to Tab C.

  5. #5
    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: vba code to apply a macro to a specific tab

    In that case, you probably need a With ... End With construct.

    Something like:

    Please Login or Register  to view this content.

    Be useful to see your code.


    Regards, TMS

+ 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