IF blank macro
MZ Tools makes life easier for the Excel VBA coder
Thanks Thanks:  0
Likes Likes:  0
Results 1 to 2 of 2

Thread: IF blank macro

  1. #1
    New Member
    Join Date
    Mar 2002
    Posts
    20
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

     
    I have this formula
    If Textbox1 = "" Then
    MsgBox "Field must be answered before you can proceed"
    Exit Sub
    End If

    This prevents the next stage when Ok is pressed however th rest of the macro still contiues how do I stop the macro when the cell is blank?

  2. #2
    Rest in Peace
    Join Date
    Feb 2002
    Posts
    1,582
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

      
    Are you calling this from another Procedure?? The Exit Sub will exit the Procedure it is housed in but go straight back to the calling procedure. You could use

    The End statement instead but this would unload the UserForm (if you are using one) and destroy all variables. Use a Boolean at the Project level.

    EG
    At the very top of a standard module put:

    Public bCarryOn as Boolean

    Then use:

    bCarryOn= True
    If Textbox1 = "" Then
    MsgBox "Field must be answered before you can proceed"
    bCarryOn= True
    Exit Sub
    End If


    And then use a simple If statement in your calling Procedure to Exit that Sub if it's True.






User Tag List

Like this thread? Share it with others

Like this thread? Share it with others

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

 

 
DMCA.com