+ Reply to Thread
Results 1 to 7 of 7

Running Macro from another sheet but referring to Active Worksheet

  1. #1
    Registered User
    Join Date
    03-28-2013
    Location
    South Africa
    MS-Off Ver
    Excel 2007
    Posts
    8

    Running Macro from another sheet but referring to Active Worksheet

    Hi,

    This is day 3 of me learning VBA and I am trying to learn it by doing practical work.

    So I started writing a macro for a sheet called "MealCal", once I had it working on that sheet, I then decided I needed to run it from another sheet called "Meal Schedule" because that sheet will pull the data results from the sheet called "MealCal" via vlookup and give us a nice summary.

    MY problem is when I started running it from the sheet "Meal Schedule" it does not paste the first row of Sheets("14 Room 09-14") into A1 of sheet "MealCal" instead is pastes it in from row A6 down and the next column again starts from row B6.

    BUT when I run the macro from "MealCal" it starts at the top at A1.

    I have got a problem with understanding referring to active sheet yet working from another sheet, Please could you help me with the code below. The code starts pasting in row6 of sheet "MealCal" from the second last line in the below code.

    Please Login or Register  to view this content.

  2. #2
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Running Macro from another sheet but referring to Active Worksheet

    This is just meant to demonstrate the connecting of sheet names to commands. You should connect ALL commands to worksheets, by name or by variable, keeps many a bad things from happening when you do.

    Please Login or Register  to view this content.
    _________________
    Microsoft MVP 2010 - Excel
    Visit: Jerry Beaucaire's Excel Files & Macros

    If you've been given good help, use the icon below to give reputation feedback, it is appreciated.
    Always put your code between code tags. [CODE] your code here [/CODE]

    ?None of us is as good as all of us? - Ray Kroc
    ?Actually, I *am* a rocket scientist.? - JB (little ones count!)

  3. #3
    Registered User
    Join Date
    03-28-2013
    Location
    South Africa
    MS-Off Ver
    Excel 2007
    Posts
    8

    Re: Running Macro from another sheet but referring to Active Worksheet

    Hi, JBeaucaire

    Thanks so much for the help, my macro is now working properly for your above help.

  4. #4
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Running Macro from another sheet but referring to Active Worksheet

    Awesome! Thanks for letting me know, and for the reputation feedback.

  5. #5
    Registered User
    Join Date
    03-28-2013
    Location
    South Africa
    MS-Off Ver
    Excel 2007
    Posts
    8

    Re: Running Macro from another sheet but referring to Active Worksheet

    Hi JBeaucaire,

    I have just run into a problem with this code which you gave me earlier, I am needing to copy the rows to the other sheet but it needs to be paste as values. How would I change the below code to make it paste as a value? When I paste Selection.PasteSpecial Paste:=xlPasteValues at then end of the below code it just gives me errors.

    Please Login or Register  to view this content.

  6. #6
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Running Macro from another sheet but referring to Active Worksheet

    It takes two lines of code to do that:
    Please Login or Register  to view this content.

  7. #7
    Registered User
    Join Date
    03-28-2013
    Location
    South Africa
    MS-Off Ver
    Excel 2007
    Posts
    8

    Re: Running Macro from another sheet but referring to Active Worksheet

    Works perfectly, thanks a mil.

+ 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. Make a macro run on only a specified worksheet regardless of which sheet is active.
    By Ethanrholt in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 09-18-2014, 12:18 PM
  2. Referring to active sheet
    By jonastjader in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 01-12-2014, 11:12 PM
  3. [SOLVED] Active Sheet not automatically running macro
    By RichTea88 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 01-10-2014, 06:54 AM
  4. Referring to active sheet
    By jonastjader in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 12-10-2013, 11:26 AM
  5. [SOLVED] Macro running on active sheet instead of sheet defined in macro
    By davegscott in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 02-19-2013, 02:04 PM

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