Try this
Code:
Private Sub Workbook_BeforeClose(Cancel As Boolean) Dim FilledCellCount As Long
Dim lngRows As Long
Const SheetContainingtheCells As String = "Sheet2"
Const CellsToCheck As String = "M|:O|"
For lngRows = 5 To 150
If Not IsEmpty(Worksheets(SheetContainingtheCells).Range("G" & lngRows)) Then
FilledCellCount = WorksheetFunction.CountA(Worksheets(SheetContainingtheCells).Range(Replace(CellsToCheck, "|", lngRows)))
If FilledCellCount < 3 Then
Cancel = True
MsgBox "Since you filled the Range 'G" & lngRows & _
"' then you must fill in the corresponding cells in the range - " & Replace(CellsToCheck, "|", lngRows), vbExclamation
Exit Sub
End If
End If
Next lngRows
End Sub
Bookmarks