I have excel Worksheet where I used the following vba code, to check on empty records:
Private Sub Workbook_BeforeClose(Cancel As Boolean)
On Error GoTo NoBlanks
Dim sh As Worksheet, lastRow As Long, lastCol As Long, emptyCells As Range
Set sh = ActiveSheet 'use here your sheet
lastRow = sh.Range("A" & Rows.Count).End(xlUp).Row
lastCol = sh.Cells(1, Columns.Count).End(xlToLeft).Column
Set emptyCells = sh.Range(sh.Cells(1, 1), sh.Cells(lastRow,
lastCol)).SpecialCells(xlCellTypeBlanks)
If emptyCells.Cells.Count > 0 Then
MsgBox "There are empty cells, which must be filled: " & emptyCells.Address(0, 0)
emptyCells.Select
Else
Resume Next
Exit Sub
End If
NoBlanks:
Resume Next
End Sub
But it still lets me exit out of the Worksheet, even if there empty records
Are there any ways to modify this code - so it wouldn't be possible to close my Worksheet before the records are filled with values?
(I used this code on "Before Close" event)