Mac – VBA making cells mandatory based on previous cell entry

macrosmicrosoft excelvba

Is there a way of making a number of cells mandatory based on the entry of a cell? The cell contents may vary.

Best Answer

You would create a "BeforeSave" sub in your workbook VBA. To do this:

  • Open Excel VBA (Alt+F11)
  • Click ThisWorkbook
  • There are two bars above the code window, click the first bar and select "Workbook"
  • Click the second bar and click "Before save" This will fill in your sub for you

Then add the following (Assuming Cell 1A was to be your reference cell and 2A was mandatory):

    If Not IsEmpty(Cells(1,1)) Then
       If Cells(2,1).Value = "" Then
          MsgBox "Cell 2A requires user input before saving"
          Cancel = True
       End if
    End if  

You can then just add elses for any other cells you want to check

Related Question