+ Reply to Thread
Results 1 to 5 of 5

Run Macro on different worksheet

  1. #1
    Registered User
    Join Date
    04-02-2014
    Location
    Roseville, USA
    MS-Off Ver
    Excel 2013
    Posts
    15

    Run Macro on different worksheet

    Hi - My Excel 2013 Spreadsheet/Workbook has two sheets, Tool and Positions. The Positions sheet is simply a number of columns with filters applied. I created checkboxes that call macros that apply filtering. Everything works perfectly fine as long as the checkboxes are on the Positions sheet where the data is. Issue is - I need the checkboxes on the Tool sheet. I have searched for a few hours now and cannot seem to find what I have to think is a small bit of code that let's me create the checkboxes on the Tool sheet while having the macro on the checkbox run on the Positions sheet. My macro code follows:

    Please Login or Register  to view this content.
    To reiterate the code above is on the checkboxes that are sitting on the Positions sheet. I need tthe checkboxes on the Tool sheet. Is there a line of code or two I can add to the code above allowing me to create the checkboxes on the Tool sheet and tell the marco to run on the Positions sheet where the filtered data is?

    Thanks in advance for any assistance.
    Last edited by Leith Ross; 04-02-2014 at 09:44 PM. Reason: Added Code Tags

  2. #2
    Valued Forum Contributor adyteo's Avatar
    Join Date
    01-10-2013
    Location
    Calgary
    MS-Off Ver
    Excel 2010
    Posts
    540

    Re: Run Macro on different worksheet

    you probably have the macro under the Positions sheet. what you need is to move that code to Tools sheet and make sure that the codes (AppBarYes and AppBarNo) are in a Module, not under a sheet, in order for them to work.
    Click on the star if you think I helped you

  3. #3
    Registered User
    Join Date
    04-02-2014
    Location
    Roseville, USA
    MS-Off Ver
    Excel 2013
    Posts
    15

    Re: Run Macro on different worksheet

    Thank you adyteo. I think I completed what you stated - I added a checkbox named AppBar to the Tool sheet and when in design mode selected the checkbox, added the code above and saved. I now see the cde in VBA under Microsoft Excel Objects - Sheet1 (Tool) and in Module1. Module 2 looks to be referencing the macro's and the cell range the macro's call. That seems to be the issue.

    Using the checkbox as a user would produces the error "We couldn't do this for the selected renge of cells. Select a sinble cell withing a range of data and then try again." Selecting debug brings me to VBA, on the Tool sheet object within the AppBar macro:
    Module2 page within the area calling the AppBar marco:

    Sub AppBarYes()
    '
    ' AppBarYes Macro
    ' AppBarYes
    '

    '
    Range("H1").Select
    ActiveSheet.Range("$D$1:$Q$381").AutoFilter Field:=4, Criteria1:="Yes"
    End Sub

    ActiveSheet.Range...ect...is the hilighting error.

    Again it appears that Excel is trying to run the code on the active sheet (which is the Tool sheet where the checkbox is) and not the Positions sheet where the data to be filtered is.

    Any guesses?

  4. #4
    Valued Forum Contributor adyteo's Avatar
    Join Date
    01-10-2013
    Location
    Calgary
    MS-Off Ver
    Excel 2010
    Posts
    540

    Re: Run Macro on different worksheet

    insert a line like this:
    Please Login or Register  to view this content.

  5. #5
    Registered User
    Join Date
    04-02-2014
    Location
    Roseville, USA
    MS-Off Ver
    Excel 2013
    Posts
    15

    Re: Run Macro on different worksheet

    adyteo - perfect, that worked.

+ 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] 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
  2. 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
  3. Excel 2010 Macro to copy worksheet, update formula and rename worksheet
    By madmak0203 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 08-29-2012, 09:18 PM
  4. Replies: 1
    Last Post: 08-29-2012, 07:11 PM
  5. [SOLVED] Macro to copy cells from one worksheet to another copies worksheet data as image instead??
    By michaeljoeyeager in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 07-13-2012, 11:26 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