I am creating an excel sheet where if the user has filled a cell in column A, he has to fill input also on column B, C and D, otherwise, he shouldn't be able to save and close the file.
Does someone have an idea on how could be this enabled?
Yes
In the workbook code module. If you want to check all or most sheets, there's an easy way to do that also (edited a typo)
Option Explicit
Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
Cancel = NotOkay
End Sub
Private Sub Workbook_BeforeClose(Cancel As Boolean)
Cancel = NotOkay
End Sub
Private Function NotOkay() As Boolean
Dim rColA As Range, rCell As Range
NotOkay = False
With Worksheets("Sheet1")
Set rColA = Nothing
On Error GoTo 0
Set rColA = Intersect(.UsedRange, .Columns(1))
On Error GoTo 0
End With
If rColA Is Nothing Then Exit Function
For Each rCell In rColA.Cells
If IsEmpty(rCell) Then GoTo NextCell
With rCell
If IsEmpty(.Offset(0, 1)) Then
Call MsgBox("Cell " & .Offset(0, 1).Address & " is empty", vbCritical + vbOKOnly, "Check Cells")
NotOkay = True
Exit Function
ElseIf IsEmpty(.Offset(0, 2)) Then
Call MsgBox("Cell " & .Offset(0, 2).Address & " is empty", vbCritical + vbOKOnly, "Check Cells")
NotOkay = True
Exit Function
ElseIf IsEmpty(.Offset(0, 3)) Then
Call MsgBox("Cell " & .Offset(0, 1).Address & " is empty", vbCritical + vbOKOnly, "Check Cells")
NotOkay = True
Exit Function
End If
End With
NextCell:
Next
End Function