Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
 
Posts: n/a
Default 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   Report Post  
Don Guillett
 
Posts: n/a
Default

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

wrote in message
ups.com...
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
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Subtotal has stopped working Tim Mc Excel Worksheet Functions 3 July 21st 05 04:20 PM
Drop-down boxes stopped working Dave Excel Discussion (Misc queries) 1 April 4th 05 06:13 PM
Excel cell references to 2nd worksheet stopped working StardustMM Excel Worksheet Functions 1 February 11th 05 04:31 PM
text to speech stopped working in excel helpmax Excel Discussion (Misc queries) 1 January 27th 05 04:19 AM
In-cell dropdown for validation stopped working Ourbriards Excel Worksheet Functions 3 December 17th 04 09:21 PM


All times are GMT +1. The time now is 05:30 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"