+ Reply to Thread
Results 1 to 12 of 12

Control a Macro from Different Worksheet

  1. #1
    Registered User
    Join Date
    11-07-2013
    Location
    Clitheroe
    MS-Off Ver
    2016
    Posts
    29

    Control a Macro from Different Worksheet

    I have downloaded a worksheet ('Data') which can access Yahoo for stock prices. The macro which runs this is controlled from a button on the worksheet "Download Prices". It works perfectly.
    I use this data downloaded from Yahoo on another worksheet ('Mystocks') in the same workbook.

    I want to run that macro using a new button on the 'Mystocks' sheet, so that I don't have to keep moving to the 'Data' sheet.
    I have tried copying and pasting the button and tried creating a new button on 'Mystocks' without success. I've tried recording a macro to 'push' the button on the 'Data' sheet without success.

    Can anyone suggest a solution?

  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
    48,155

    Re: Control a Macro from Different Worksheet

    Can anyone suggest a solution?
    Not without seeing the workbook and code.
    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 Expert
    Join Date
    04-01-2013
    Location
    East Auckland
    MS-Off Ver
    Excel 365
    Posts
    1,347

    Re: Control a Macro from Different Worksheet

    Cross posted. Norie is already talking to him

    https://www.mrexcel.com/forum/excel-...worksheet.html
    If you want something done right... find a forum and ask an online expert.

    Time flies like an arrow. Fruit flies like a banana.

  4. #4
    Registered User
    Join Date
    11-07-2013
    Location
    Clitheroe
    MS-Off Ver
    2016
    Posts
    29

    Re: Control a Macro from Different Worksheet

    TMS,

    Here is the content of the module. I'm unsure how to post the 'workbook'



    Please Login or Register  to view this content.
    Last edited by steveal; 05-04-2017 at 06:42 PM.

  5. #5
    Forum Expert
    Join Date
    04-01-2013
    Location
    East Auckland
    MS-Off Ver
    Excel 365
    Posts
    1,347

    Re: Control a Macro from Different Worksheet

    put your code in code tags

    Please read the forum rules you are breaking quite a lot of them.

    also it says
    Please Login or Register  to view this content.
    but probably you want to name the data sheet if you are trying to run it from a sheet that isn't the data sheet.

  6. #6
    Registered User
    Join Date
    11-07-2013
    Location
    Clitheroe
    MS-Off Ver
    2016
    Posts
    29

    Re: Control a Macro from Different Worksheet

    Quote Originally Posted by scottiex View Post
    Cross posted. Norie is already talking to him

    https://www.mrexcel.com/forum/excel-...worksheet.html
    Yes. I'm sorry I've cocked things up. I thought I had reached a dead end and Norie was still helping.

  7. #7
    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
    48,155

    Re: Control a Macro from Different Worksheet

    I thought I had reached a dead end and Norie was still helping.
    Not really the point. If you post on multiple forums or sub-forums, you need to tell people so they have the full picture and don't waste time unnecessarily.

    Attach a sample workbook. Make sure there is just enough data to demonstrate your need. Include a BEFORE sheet and an AFTER sheet in the workbook if needed to show the process you're trying to complete or automate. Make sure your desired results are shown, mock them up manually if necessary.

    Remember to desensitize the data.

    Click on GO ADVANCED and then scroll down to Manage Attachments to open the upload window.


    Your post does not comply with Rule 3 of our Forum RULES. Use code tags around code.

    Posting code between [CODE]Please [url=https://www.excelforum.com/login.php]Login or Register [/url] to view this content.[/CODE] tags makes your code much easier to read and copy for testing, it also maintains VBA formatting.

    Click on Edit to open your thread, then highlight your code and click the # icon at the top of your post window. More information about these and other tags can be found here


    Please take some time to read the forum rules. Most forums will have their own variations on a theme so it's worth while becoming familiar with them.

    https://www.excelforum.com/forum-rul...rum-rules.html

  8. #8
    Registered User
    Join Date
    11-07-2013
    Location
    Clitheroe
    MS-Off Ver
    2016
    Posts
    29

    Re: Control a Macro from Different Worksheet

    Quote Originally Posted by TMS View Post
    Not really the point. If you post on multiple forums or sub-forums, you need to tell people so they have the full picture and don't waste time unnecessarily.

    Attach a sample workbook. Make sure there is just enough data to demonstrate your need. Include a BEFORE sheet and an AFTER sheet in the workbook if needed to show the process you're trying to complete or automate. Make sure your desired results are shown, mock them up manually if necessary.

    Remember to desensitize the data.

    Click on GO ADVANCED and then scroll down to Manage Attachments to open the upload window.


    Your post does not comply with Rule 3 of our Forum RULES. Use code tags around code.

    Posting code between [CODE]Please [url=https://www.excelforum.com/login.php]Login or Register [/url] to view this content.[/CODE] tags makes your code much easier to read and copy for testing, it also maintains VBA formatting.

    Click on Edit to open your thread, then highlight your code and click the # icon at the top of your post window. More information about these and other tags can be found here


    Please take some time to read the forum rules. Most forums will have their own variations on a theme so it's worth while becoming familiar with them.

    https://www.excelforum.com/forum-rul...rum-rules.html
    Sorry, I'm completely out of my depth here.
    Please delete the thread.

  9. #9
    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
    48,155

    Re: Control a Macro from Different Worksheet

    We're happy to help. In fact, Norie is a senior member here too AND this forum allows you to upload a sample workbook.

    So, don't panic. Just take a little time to read each of the points in my last post and we can help you with a solution.

  10. #10
    Registered User
    Join Date
    11-07-2013
    Location
    Clitheroe
    MS-Off Ver
    2016
    Posts
    29

    Re: Control a Macro from Different Worksheet

    Quote Originally Posted by TMS View Post
    We're happy to help. In fact, Norie is a senior member here too AND this forum allows you to upload a sample workbook.

    So, don't panic. Just take a little time to read each of the points in my last post and we can help you with a solution.
    TMS,

    Thanks for persevering!
    I've put the code in tags. I've simplified the workbook and will attempt to attach it.
    It consists of just 2 worksheets.
    - The Data sheet which does the correct downloading using the form button on the page. To use:
    1. Put a new stock ticker at the bottom of the list in column A (use MSFT or AAPL or CSCO or ADT.L etc.).
    2. Press the download button and the relevant data will be downloaded.

    - The Mystocks worksheet which simply takes some of the downloaded date from the Data worksheet. I've created another form button on the Mystocks sheet.
    I want that new button to run the original macro on the Data sheet.
    Attached Files Attached Files
    Last edited by steveal; 05-05-2017 at 01:04 AM.

  11. #11
    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
    48,155

    Re: Control a Macro from Different Worksheet

    Change your code to the following. You can then assign it to your button on the MyData sheet. It will still run from the Data sheet.

    Please Login or Register  to view this content.
    You probably need to comment out the following line:

    Please Login or Register  to view this content.

  12. #12
    Registered User
    Join Date
    11-07-2013
    Location
    Clitheroe
    MS-Off Ver
    2016
    Posts
    29

    Re: Control a Macro from Different Worksheet

    TWS,

    Perfect!
    I did comment out the line you suggested to remain on the Mystocks sheet.

    Thanks for the help and the education!
    I'll compare your code to the original and try to learn a little more.
    Last edited by steveal; 05-05-2017 at 02:19 PM.

+ 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. Need help with macro for filtering worksheet data based on combobox control
    By preetypj in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 09-03-2014, 07:28 AM
  2. Replies: 6
    Last Post: 08-06-2012, 10:53 AM
  3. Creating a worksheet to control which cells a macro sums
    By luke.guthrie in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 06-07-2012, 09:58 AM
  4. macro assigned to a form control button in a protected worksheet
    By lee_har in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 10-09-2009, 02:29 AM
  5. Help with clear worksheet macro problem on a stock control spreadsheet
    By jilkin in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 09-10-2009, 02:12 AM
  6. [SOLVED] Navigate a worksheet when under control of a macro....
    By Neal Zimm in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 09-27-2005, 09:05 AM
  7. Can I control Macro run automatically current worksheet?
    By Microlong in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 03-02-2005, 09:06 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