+ Reply to Thread
Results 1 to 8 of 8

Sub Routine running

Hybrid View

  1. #1
    Registered User
    Join Date
    08-19-2013
    Location
    USA
    MS-Off Ver
    Excel 2003
    Posts
    27

    Sub Routine running

    Is this a way to see if a subroutine is running or not. I have a subroutine that I run and it does calculations and enters the data into a spreadsheet. I would like to run all but a couple of lines of this code a second time based on another subroutine being true. Is this possible. I was thinking that I should just be able to look and see if sub xxxx is true or not.

  2. #2
    Forum Contributor
    Join Date
    03-04-2014
    Location
    Canada Eh
    MS-Off Ver
    Excel 2010
    Posts
    199

    Re: Sub Routine running

    Hi mjwakema, your question is a little vague so my answer may come across as vague too but the following may help with understanding this:
    Sub PrimaryRoutine()
        '*********************************************************'
        '**Your code that needs to run before Sub-Routine call  **'
        '**goes here                                            **'
        '*********************************************************'
        
        'Call SubRoutine1
        If SubRoutine2 = True Then
            SubRoutine1
        Else
            SubRoutine3
        End If
        
    End Sub
    
    
    Sub SubRoutine1()
        'code goes here
    End Sub
    
    Function SubRoutine2() As Boolean
        'code goes here
    End Function
    
    Sub SubRoutine3()
        'code goes here
    End Sub
    If you want something specific, you'll need to be more specific.

    Also, you can add break lines to your code by clicking the specific line of code and the pressing F9. When the code runs it will stop at the chosen line.
    Click the * to give Rep to a post you like.

  3. #3
    Registered User
    Join Date
    08-19-2013
    Location
    USA
    MS-Off Ver
    Excel 2003
    Posts
    27

    Re: Sub Routine running

    Thank you for the reply, This is what I am looking for, but I have tried this and I get a variable not defined. It is seeing my subroutine name as a variable not a subroutine. The name of my sub is sub ActualHoursCB_Click(). I tried calling If ActualHoursCB_Click = true then. This does not work. Any thoughts?

  4. #4
    Forum Contributor
    Join Date
    03-04-2014
    Location
    Canada Eh
    MS-Off Ver
    Excel 2010
    Posts
    199

    Re: Sub Routine running

    You'll have to post all the code involved for me to try and give you my thoughts. Don't forget code-tags around your code.

  5. #5
    Registered User
    Join Date
    08-19-2013
    Location
    USA
    MS-Off Ver
    Excel 2003
    Posts
    27

    Re: Sub Routine running

    Sorry if I am causing confusion. I just want to know if it is possible to check and see if a certain procedure is running or not regardless of any other code involved. I would think it would be like checking to see is a program like word or something is opened or not. So I would just like to know is it possible if so how to you write a subroutine name into an if then statement.

    thank you for your time on this.

  6. #6
    Forum Contributor
    Join Date
    03-04-2014
    Location
    Canada Eh
    MS-Off Ver
    Excel 2010
    Posts
    199

    Re: Sub Routine running

    If you don't want to put in break lines like I suggested, just put a message box in the routines and they'll pop up when the routine is called:
    Sub ActualHoursCB_Click()
        MsgBox "This Sub-Routine is running", , ""
        'Your code is here
    End Sub

  7. #7
    Forum Guru Izandol's Avatar
    Join Date
    03-29-2012
    Location
    *
    MS-Off Ver
    Excel 20(03|10|13)
    Posts
    2,581

    Re: Sub Routine running

    A subroutine does not return a value - you must use Function to return value. If you have subroutine that is running for a long time you may use public variable but first routine must have DoEvents or similar code or second routine will not run.:
    Public IsRunning As Boolean
    
    Sub ActualHoursCB_Click()
    IsRunning = True
    Do
    ' some code
    DoEvents
    Loop
    IsRunning = False
    End Sub
    
    Sub otherRoutine()
    If IsRunning Then
    ' some code
    End If
    End Sub
    • Please remember to mark threads Solved with Thread Tools link at top of page.
    • Please use code tags when posting code: [code]Place your code here[/code]
    • Please read Forum Rules

  8. #8
    Registered User
    Join Date
    08-19-2013
    Location
    USA
    MS-Off Ver
    Excel 2003
    Posts
    27

    Re: Sub Routine running

    Thank you Izandol. Set a variable to be true when the procedure is running. Way to simple. I should never try to program before my morning coffee! I was trying to make it way more difficult than it needed to be.

    Thank you!!

+ 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. Pass a variable from one sub-routine to another sub-routine
    By gowtham_pec in forum Excel Programming / VBA / Macros
    Replies: 12
    Last Post: 05-01-2013, 07:07 PM
  2. Excel sometimes crashes when running a sub routine
    By Brunstgnegg in forum Excel Programming / VBA / Macros
    Replies: 27
    Last Post: 08-20-2010, 06:55 AM
  3. Why won't this routine run?
    By cmcgath in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 02-17-2009, 03:41 PM
  4. [SOLVED] Routine running slow (memory leak?)
    By ExcelMonkey in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 02-01-2006, 07:25 AM
  5. How to prevent routine from running on certain sheets
    By Gary Paris in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 02-08-2005, 12:06 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