vivekvasan
New Member
- Joined
- Feb 16, 2017
- Messages
- 12
Hello Experts,
I'm trying to tinker with a code that would prevent workbook from closing if the cells in a particular row range are not filled based on first cell criteria. Here is the code so far.. Please share your thoughts/ corrections. Thanks.
Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
Dim ws As Worksheet
Dim Rvalue As Range
Set ws = Sheets("sheet1")
If ws.Range("A" & Rows.Count).End(xlUp).Offset(1).Value = "Complete" Then
If WorksheetFunction.CountA("B3:X7") = 0 Then
Cancel = True
MsgBox "Cell areas for a completed row cannot be left blank"
Else: ActiveWorkbook.Close Savechanges:=True
End If
End If
End Sub
I'm trying to tinker with a code that would prevent workbook from closing if the cells in a particular row range are not filled based on first cell criteria. Here is the code so far.. Please share your thoughts/ corrections. Thanks.
Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
Dim ws As Worksheet
Dim Rvalue As Range
Set ws = Sheets("sheet1")
If ws.Range("A" & Rows.Count).End(xlUp).Offset(1).Value = "Complete" Then
If WorksheetFunction.CountA("B3:X7") = 0 Then
Cancel = True
MsgBox "Cell areas for a completed row cannot be left blank"
Else: ActiveWorkbook.Close Savechanges:=True
End If
End If
End Sub