+ Reply to Thread
Results 1 to 7 of 7

Macro only runs correctly from specific sheet

  1. #1
    Forum Contributor
    Join Date
    06-28-2018
    Location
    New York
    MS-Off Ver
    MS Office 2010
    Posts
    184

    Macro only runs correctly from specific sheet

    Hi all,

    The below is a portion of code that appears to be working (I'm sure it is far from the most efficient). The issue is that the code only runs correctly (e.g. returns the desired result) when run from a specific sheet ("Sales Calc"). Any help would be greatly appreciated. Thank you.



    Please Login or Register  to view this content.

  2. #2
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS365 Family 64-bit
    Posts
    24,721

    Re: Macro only runs correctly from specific sheet

    What module contains this code?

    What does the code do incorrectly when it is not run from sheet "Sales Calc"?

    You have qualified all your references except a couple, and your problem is probably in those couple. See my notes below.

    Please Login or Register  to view this content.
    Jeff
    | | |會 |會 |會 |會 | |:| | |會 |會
    Read the rules
    Use code tags to [code]enclose your code![/code]

  3. #3
    Forum Contributor
    Join Date
    06-28-2018
    Location
    New York
    MS-Off Ver
    MS Office 2010
    Posts
    184

    Re: Macro only runs correctly from specific sheet

    Thank you for taking the time to look at this 6StringJazzer.

    So I believe this is in a standard module and is basically filtering a column on sales calc and moving/copying certain filtered column data from that sheet to another sheet (New Inv Ids).

    In short, when this code is run from the sales calc tab it correctly copies the filtered/visible cells below the header and pastes/transfers to the New Inv Id tab.
    If the code is run from another sheet it grabs the correct column but from the header to the top of the sheet (not the data below).

    The below might be a little cleaner but is still not working when run from another sheet.


    Please Login or Register  to view this content.
    Last edited by nickytraps; 08-19-2019 at 01:27 PM.

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

    Re: Macro only runs correctly from specific sheet

    This will give you the row number of the sheet that is active when you run the code.
    Please Login or Register  to view this content.
    This will give you the row number of the sheet as in the code line even if another sheet is the active sheet when running the code.
    Please Login or Register  to view this content.
    Depending on what you want to do, you might want to change to reference the right sheet.

  5. #5
    Forum Contributor
    Join Date
    06-28-2018
    Location
    New York
    MS-Off Ver
    MS Office 2010
    Posts
    184

    Re: Macro only runs correctly from specific sheet

    Thank you jolivanes! I switched the last row command and it seems to be working fine.

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

    Re: Macro only runs correctly from specific sheet

    Good to hear that you have it under control.
    I made this for you so I might as well show it.

    To illustrate the problem:
    In an empty workbook, fill Sheet1, Column C from 1 to 25 with data.
    Fill Sheet2, Column C from 1 to 20 with data.
    Fill Sheet3, Column C from 1 to 15 with data.

    Paste both macros into Module1.
    Run this macro from any sheet and you will get the right results.
    Please Login or Register  to view this content.

    Now have Sheet1 as active sheet and run this macro.
    Please Login or Register  to view this content.
    Go to Sheet2 to see the result.

  7. #7
    Forum Contributor
    Join Date
    06-28-2018
    Location
    New York
    MS-Off Ver
    MS Office 2010
    Posts
    184

    Re: Macro only runs correctly from specific sheet

    I got it. Thank you for taking the time to help both with my original question and teaching me something new. Much appreciated!

+ 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] VBA runs on all active sheets and I only want it to run on 1 specific sheet
    By Doolski in forum Excel Programming / VBA / Macros
    Replies: 12
    Last Post: 05-16-2017, 10:39 PM
  2. [SOLVED] Macro code that runs despite specific cells being locked.
    By TBM in forum Excel Programming / VBA / Macros
    Replies: 23
    Last Post: 01-26-2016, 08:56 PM
  3. [SOLVED] Macro runs correctly when run from Editor, but not from Command Button??
    By Nola111 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 05-20-2014, 02:20 PM
  4. Save As Macro runs on opening specific workbook
    By Eline in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 10-10-2013, 09:04 AM
  5. [SOLVED] Macro only runs on specific sheet name
    By cymraeg in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 05-28-2013, 03:43 PM
  6. Error when running macro at a specific time: only runs once
    By Axildoofay in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 04-09-2013, 05:54 AM
  7. Macro runs when i click on specific cell
    By Macdave_19 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 08-19-2009, 05:28 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