+ Reply to Thread
Results 1 to 5 of 5

Change macro to work on a different sheet

  1. #1
    Forum Contributor
    Join Date
    06-28-2004
    MS-Off Ver
    Home/Office 2016
    Posts
    246

    Change macro to work on a different sheet

    The current macro - BreakdownPlaces will only work on the sheet that you are on.

    I want to run a new macro BreakdownPlacesJunior and have it run on the ResultsJunior sheet
    even if I am on the Results Open sheet (same for Open and Pleasure)

    Basically have three copies of the BreakdownPlaces macro and have them point to each of the 3 tabs

    {see attached}
    Attached Files Attached Files
    Last edited by x65140; 12-22-2014 at 07:23 AM.

  2. #2
    Forum Expert
    Join Date
    10-06-2008
    Location
    Canada
    MS-Off Ver
    2007 / 2013
    Posts
    5,543

    Re: Change macro to work on a different sheet

    There are a few ways to run a macro in another sheet from whichever sheet.

    Please Login or Register  to view this content.
    will put Hallo in cell A1 in the active sheet, in other words the sheet that is visible. Can be any sheet

    Please Login or Register  to view this content.
    Will put Hallo in cell A1 in Sheet2 only. Macro can be run from any sheet.

    Please Login or Register  to view this content.
    Will put Hallo in cell A1 in Sheet2 only. Macro can be run from any sheet.

    It is often required to use the reference multiple times in one line.
    For instance
    Please Login or Register  to view this content.
    Following is an example from Smallman. Notice the use of ws multiple times.
    Please Login or Register  to view this content.
    The following is from
    http://msdn.microsoft.com/en-us/library/wc500chb.aspx
    By using With...End With, you can perform a series of statements on a specified object without
    specifying the name of the object multiple times. Within a With statement block, you can specify a
    member of the object starting with a period, as if the With statement object preceded it.
    For example, to change multiple properties on a single object, place the property assignment
    statements inside the With...End With block, referring to the object only once instead of once for each
    property assignment.
    If your code accesses the same object in multiple statements, you gain the following benefits by using
    the With statement:
    You don't need to evaluate a complex expression multiple times or assign the result to a temporary
    variable to refer to its members multiple times.
    You make your code more readable by eliminating repetitive qualifying expressions.

  3. #3
    Valued Forum Contributor fredlo2010's Avatar
    Join Date
    07-04-2012
    Location
    Miami, United States
    MS-Off Ver
    Excel 365
    Posts
    762

    Re: Change macro to work on a different sheet

    Hello,

    I refactored most of your code so it can be applied to different sheet. In addition to Jolivanes suggestion you should read this article on passing variables and arguments.
    http://www.homeandlearn.org/passing_..._to_a_sub.html

    Replace all your code with the code I provided. I was not able to test this because I am missing a sheet.

    Hope this gets you on the right track.

    Please Login or Register  to view this content.

  4. #4
    Forum Guru
    Join Date
    03-02-2006
    Location
    Los Angeles, Ca
    MS-Off Ver
    WinXP/MSO2007;Win10/MSO2016
    Posts
    12,629

    Re: Change macro to work on a different sheet

    Please Login or Register  to view this content.
    Ben Van Johnson

  5. #5
    Forum Contributor
    Join Date
    06-28-2004
    MS-Off Ver
    Home/Office 2016
    Posts
    246

    Re: Change macro to work on a different sheet

    Wow! Thanks for all the help guys!

+ 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. [SOLVED] How to make the macro work for all rows in the work sheet
    By Valli nayaki in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 02-18-2013, 10:43 PM
  2. MAcro does not work when certain cells in a work sheet are protected
    By Unnati in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 12-10-2012, 03:38 AM
  3. Sheet Change Event wont work
    By Strugglin in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 02-02-2009, 10:35 AM
  4. Replies: 2
    Last Post: 07-11-2006, 11:15 PM
  5. can't change font in work sheet
    By Dumber than a pocket full of rocks in forum Excel - New Users/Basics
    Replies: 2
    Last Post: 07-06-2006, 02:35 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