+ Reply to Thread
Results 1 to 6 of 6

HELP - run macro from any worksheet

  1. #1
    Registered User
    Join Date
    05-24-2015
    Location
    London
    MS-Off Ver
    2010
    Posts
    35

    Post HELP - run macro from any worksheet

    Hi

    I was hoping someone could help as I have a code that works fine on one sheet but not on other worksheets. Can someone give me some advice on how I can change it so it runs in whichever worksheet I like please?

    I have the following code and it works when I run it from a worksheet entitled "Active List". However I want to run it from another worksheet call "Full List" (completely unrelated worksheet but this is where I want to run all my macros from), but it comes back with a 'Run Time Error 1004 'Application Defined or Object Defined Error'.


    Please Login or Register  to view this content.
    The error is associated with the following line:

    Please Login or Register  to view this content.
    I have attached an example of my issue. You will notice 4 visible tabs.

    If you press the "Run All Macros" button on the first tab entitled "Full List" you will note the error coming up. However if you turn to tab entitled "Active List" where I have that specific code only (and it relates to that tab), it works fine.

    The question I have is how do I modify the code so it runs from the first tab entitled "Full List" ??(or indeed any tab).

    The overall objective of the code is to extract data based on specific headings (in this case numbers) into different tabs using one macro. It works, but is having issues when I change the tab it is run from.

    Hope you can help

  2. #2
    Forum Guru Kaper's Avatar
    Join Date
    12-14-2013
    Location
    Warsaw, Poland
    MS-Off Ver
    most often: Office 365 in Windows environment
    Posts
    8,623

    Re: HELP - run macro from any worksheet

    seems that your with - end with was too deeply nested, you probably need to have it surrounding all the code and don't forget about dot-qualified .range or .cells
    Please Login or Register  to view this content.
    Best Regards,

    Kaper

  3. #3
    Registered User
    Join Date
    05-24-2015
    Location
    London
    MS-Off Ver
    2010
    Posts
    35

    Re: HELP - run macro from any worksheet

    Hi Kaper

    Thanks for your reply and help.

    Unfortunately still doesn't look like it is working. Any other suggestions?

    I cant figure it out.

  4. #4
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: HELP - run macro from any worksheet

    Hello indik,

    The macro below will work on your worksheets in the posted workbook. The macro will in other workbooks as long as the source data starts 1 row below it's header row and the destination data starts 2 rows below it's header row. This can be changed if needed. The macro has been tested and worked for me. Replace the code in Module1 with the code below. Add a new module to your project and paste the Module2 code into it.

    Module1 Macro Code
    Please Login or Register  to view this content.
    Module2 Macro Code
    Please Login or Register  to view this content.
    Sincerely,
    Leith Ross

    Remember To Do the Following....

    1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.
    2. Thank those who have helped you by clicking the Star below the post.
    3. Please mark your post [SOLVED] if it has been answered satisfactorily.


    Old Scottish Proverb...
    Luathaid gu deanamh maille! (Rushing causes delays!)

  5. #5
    Registered User
    Join Date
    05-24-2015
    Location
    London
    MS-Off Ver
    2010
    Posts
    35

    Re: HELP - run macro from any worksheet

    Leith

    Many thanks for your help - it worked really well!

    However I was wondering do you know how I could adapt it so it would also work if I wanted to hide the headings row in my destination sheet? My aim is to have data extracted to the relevant columns (as it does now), but also to hide row 1, where the numbers are so my template looks more professional and avoids anyone deleting the numbers. The numbers in the destination sheet will never change, hence why I want to hide them.

    I have tried to hide row one and it doesnt work. As soon as I unhide row 1 of the destination sheet it works perfectly.

    Thanks for your help

  6. #6
    Registered User
    Join Date
    05-24-2015
    Location
    London
    MS-Off Ver
    2010
    Posts
    35

    Re: HELP - run macro from any worksheet

    Quick update - I have worked around the issue by adding in a simple unhide and hide macro either side of calling the above macros. This does the job.



    However out of interest is there a way the code could be modified simply so it searches on hidden rows?

    Also just wanted to say thank you for highlighting what your code was doing with your comments. They were very helpful.

    Many thanks

+ 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. Macro to copy data from multiple worksheet cells in to a single Master worksheet
    By thunt13 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 05-08-2015, 03:24 PM
  2. Replies: 3
    Last Post: 05-26-2014, 02:21 AM
  3. [SOLVED] Macro to Copy Master Worksheet create and paste in new auto named worksheet
    By TheRealLethality in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 04-15-2014, 12:46 AM
  4. [SOLVED] Macro/VBA code to Copy data from primary worksheet to a worksheet opened by macro
    By MHamid in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 04-30-2013, 11:10 AM
  5. Macro to select worksheet based on cell value and then return data to diff worksheet
    By clnossok in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 04-22-2013, 07:48 PM

Tags for this Thread

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