View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
mark_the_yeti[_2_] mark_the_yeti[_2_] is offline
external usenet poster
 
Posts: 10
Default Prevent closing if values do not match

Hello,

My goal is to prevent the workbook from closing if there is not a value in
Row 4, Column 4 when Row 4, Column 5 does have a value. This condition would
apply for rows 4 to 454.

I think I'm headed in the right direction, but I must be missing something...

So far I have:

Private Sub Workbook_BeforeClose(Cancel As Boolean)

For i = 4 To 454

Set hours = Worksheets("Test").Cells(i, 5)
Set task = Worksheets("Test").Cells(i, 4)

If hours = 0 Then
Cancel = False
Else
If task = 0 Then
Cancel = True
End If
End If

Next i

End Sub