+ Reply to Thread
Results 1 to 2 of 2

VB Stopped Working

  1. #1

    VB Stopped Working

    I have a simple code behind a spreadsheet that prevents it from closing
    if some conditions are not satisfied. The code is:

    Private Sub Workbook_BeforeClose(Cancel As Boolean)

    'MsgBox "Test if I am being evaluated"

    If (Range("C27") <> 3 And Range("D27") <> 2 And Range("E27") <> 1 And
    Range("F27") <> 2 And Range("G27") <> 3 _
    And Range("I27") <> 3 And Range("J27") <> 2 And Range("K27") <> 1 And
    Range("L27") <> 2 And Range("M27") <> 3 _
    And Range("C42") <> 2 And Range("D42") <> 2 And Range("E42") <> 1 And
    Range("F42") <> 2 And Range("G42") <> 2 _
    And Range("I42") <> 2 And Range("J42") <> 2 And Range("K42") <> 1 And
    Range("L42") <> 2 And Range("M42") <> 2 _
    And Range("C57") <> 2 And Range("D57") <> 2 And Range("E57") <> 1 And
    Range("F57") <> 2 And Range("G57") <> 2 _
    And Range("I57") <> 2 And Range("J57") <> 2 And Range("K57") <> 1 And
    Range("L57") <> 2 And Range("M57") <> 2) Then
    MsgBox "You must complete the survey before closing." _
    & " Please note the number of selections required per action.",
    vbExclamation, "CANNOT CLOSE"
    Cancel = True
    End If

    End Sub

    My issue is that it evaluates it a random number of times and then just
    stops evaluating it. It seems like it is getting disabled. However, I
    tried to add a msgbox at the top of the code just to see if it reads
    part of it and it does! Why is this happening? Help!

    Thanks,
    Michelle


  2. #2
    Don Guillett
    Guest

    Re: VB Stopped Working

    I tried testing and didn't have a problem. But maybe you should group
    if range("c27,g27,i27")<>3
    and perhaps you really want OR instead of AND???

    --
    Don Guillett
    SalesAid Software
    [email protected]
    <[email protected]> wrote in message
    news:[email protected]...
    > I have a simple code behind a spreadsheet that prevents it from closing
    > if some conditions are not satisfied. The code is:
    >
    > Private Sub Workbook_BeforeClose(Cancel As Boolean)
    >
    > 'MsgBox "Test if I am being evaluated"
    >
    > If (Range("C27") <> 3 And Range("D27") <> 2 And Range("E27") <> 1 And
    > Range("F27") <> 2 And Range("G27") <> 3 _
    > And Range("I27") <> 3 And Range("J27") <> 2 And Range("K27") <> 1 And
    > Range("L27") <> 2 And Range("M27") <> 3 _
    > And Range("C42") <> 2 And Range("D42") <> 2 And Range("E42") <> 1 And
    > Range("F42") <> 2 And Range("G42") <> 2 _
    > And Range("I42") <> 2 And Range("J42") <> 2 And Range("K42") <> 1 And
    > Range("L42") <> 2 And Range("M42") <> 2 _
    > And Range("C57") <> 2 And Range("D57") <> 2 And Range("E57") <> 1 And
    > Range("F57") <> 2 And Range("G57") <> 2 _
    > And Range("I57") <> 2 And Range("J57") <> 2 And Range("K57") <> 1 And
    > Range("L57") <> 2 And Range("M57") <> 2) Then
    > MsgBox "You must complete the survey before closing." _
    > & " Please note the number of selections required per action.",
    > vbExclamation, "CANNOT CLOSE"
    > Cancel = True
    > End If
    >
    > End Sub
    >
    > My issue is that it evaluates it a random number of times and then just
    > stops evaluating it. It seems like it is getting disabled. However, I
    > tried to add a msgbox at the top of the code just to see if it reads
    > part of it and it does! Why is this happening? Help!
    >
    > Thanks,
    > Michelle
    >




+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

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