PDA

View Full Version : Solved: Restrict user to close the file if a cell is blank



rajagopal
10-31-2008, 12:35 AM
When the user updates data in column F in a cell range, he has to compulsorily update the target date (Column H) in the corresponding cell range also.

Say, If the user updates data in cell F7 and not updated the target date in cell H7 and closes the file, an alert message has to pop-up (Ok). If the user click OK, the close book event has to be disabled.

I attached the sheet.

Raj

Bob Phillips
10-31-2008, 03:38 AM
Private Sub Workbook_BeforeClose(Cancel As Boolean)
Dim msg As String
Dim i As Long

With Worksheets("Action item tracker")

For i = 2 To .Cells(.Rows.Count, "F").End(xlUp).Row

If .Cells(i, "F").Value <> "" And .Cells(i, "H").Value = "" Then

msg = msg & "Row #" & i & vbNewLine
End If
Next i

If msg <> "" Then

MsgBox "Incomplete data" & vbNewLine & vbNewLine & msg
Cancel = True
End If
End With
End Sub

rajagopal
10-31-2008, 03:54 AM
this works fine. thank you.

mdmackillop
10-31-2008, 06:49 AM
Please remember to mark your threads Solved.

rajagopal
11-05-2008, 12:40 AM
Marked the thread as Solved.
Thanks.