+ Reply to Thread
Results 1 to 7 of 7

Code Works only in Debug Mode, Not When Button is Clicked.

  1. #1
    Registered User
    Join Date
    07-12-2018
    Location
    United States
    MS-Off Ver
    2016
    Posts
    10

    Code Works only in Debug Mode, Not When Button is Clicked.

    Here is the code below. It works perfectly when I step into the sub routine and continually hit F8 but not when the button is hit in the excel sheet.

    PHP Code: 
    Sub ClearFilter_Click()

      
    Dim route As Object
      Dim total
    routecountAs Integer
      total 
    0
      
    For Each route In ActiveSheet.Range("AU1: AU350")
      
    ActiveSheet.Range("D1").Clear
      x 
    route.Value
      ActiveSheet
    .Range("D1").Value x
      Data
    .Range("OutOfSequence[[#All],[WaveNumber]:[Out of Order?]]").AdvancedFilter Action:=xlFilterInPlaceCriteriaRange:=Data.Range _
    ("AO1:BZ2"), Unique:=False

    routecount 
    Application.WorksheetFunction.CountIf(Range("OutOfSequence[Out of Order?]"), "YES")

    total total routecount
    ActiveSheet
    .Range("D7") = total
      Next route
      ActiveSheet
    .Range("D7") = total
      

    End Sub 

  2. #2
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Code Works only in Debug Mode, Not When Button is Clicked.

    How does it not work when you click the button?
    If posting code please use code tags, see here.

  3. #3
    Registered User
    Join Date
    07-12-2018
    Location
    United States
    MS-Off Ver
    2016
    Posts
    10

    Re: Code Works only in Debug Mode, Not When Button is Clicked.

    It does not display the value as it should. When I debug it, and step into every time is calculates and displays as it is supposed to. When I click the button attached to the macro, it just says calculating and does not produce any results.
    Last edited by shaht96; 07-17-2018 at 02:16 PM.

  4. #4
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: Code Works only in Debug Mode, Not When Button is Clicked.

    Quote Originally Posted by shaht96 View Post
    It does not display the value as it should. When I debug it, and step into every time is calculates and displays as it is supposed to.
    It would help if we could see the workbook. You don't say what the value should be, nor what value you are getting.

    Are you sure the button is on the same sheet that you are analysing with the code. It's all to easy to have a sheet active when you step through code so that you can flip back and forth to check things. But if the button is not on the sheet in question and since you don't qualify the range "AU1: AU350" with a specific sheet name - just ActiveSheet then you will get inexpected results.
    Richard Buttrey

    RIP - d. 06/10/2022

    If any of the responses have helped then please consider rating them by clicking the small star icon below the post.

  5. #5
    Registered User
    Join Date
    07-12-2018
    Location
    United States
    MS-Off Ver
    2016
    Posts
    10

    Re: Code Works only in Debug Mode, Not When Button is Clicked.

    Unfortunately my workbook is too large to upload

  6. #6
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: Code Works only in Debug Mode, Not When Button is Clicked.

    We don't need the full size workbook. Take a copy and delete most of the data leaving just enough to replicate the problem then upload the copy.

  7. #7
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    East Sussex, UK
    MS-Off Ver
    365, varying versions/builds
    Posts
    21,274

    Re: Code Works only in Debug Mode, Not When Button is Clicked.

    What is the point of the filtering in the code?

+ 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 works OK in Step into debug mode but not doing job when run from command button
    By caabdul in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 03-10-2018, 10:16 AM
  2. [SOLVED] VBA code works in debug mode but misses steps running in normal mode
    By supereeg in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 10-18-2016, 05:42 AM
  3. VBA Code Runs in Debug Mode But Returns Type Mismatch Error Outside Debug Mode
    By valerie.k.chiang in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 01-24-2014, 03:48 PM
  4. [SOLVED] Code skips on Run Mode but runs fine on F8 (Debug Mode)
    By RaquelAR in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 11-25-2013, 01:05 PM
  5. VBA code only works correctly in Debug mode
    By tpthatsme in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 02-09-2012, 12:51 PM
  6. [SOLVED] Macro Works but not in Debug Step mode
    By Bob Smedley in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 01-31-2006, 12:35 PM
  7. [SOLVED] [SOLVED] Excel 2000 Code works except in debug mode
    By Bob Smedley in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 01-23-2006, 09:25 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