title: Make cell mandatory in excel using vba
body: <p>I have tried this code for creating mandatory fields but the problem is it is showing the error message before going to the cell.</p>
  
  <pre><code>Private Sub Worksheet_SelectionChange(ByVal Target As Range)
  
      Dim lastRow As Long
      With ActiveSheet
          lastRow = .Cells(.Rows.count, "A").End(xlUp).Row
          Dim I, J As Integer
          For I = 1 To lastRow
          If Cells(I, "C").Value = "" Then
          MsgBox "Please Enter Business Type Value", vbOKOnly
          Exit Sub
          End If
          'If Cells(I, "D").Value = "" Then
          'MsgBox "Please Enter Customer Account Code", vbOKOnly
          'Exit Sub
          'End If
          'If Cells(I, "E").Value = "" Then
          'MsgBox "Please Enter Transport Mode Value", vbOKOnly
          'Exit Sub
          'End If
          'If Cells(I, "F").Value = "" Then
          'MsgBox "Please Enter Incoterm Value", vbOKOnly
          'Exit Sub
          'End If
          'If Cells(I, "K").Value = "" Then
          'MsgBox "Please Enter From date Value", vbOKOnly
          'Exit Sub
          'End If
          'If Cells(I, "L").Value = "" Then
          'MsgBox "Please Enter To date Value", vbOKOnly
          'Exit Sub
          'End If
          'If Cells(I, "K").Value &gt; Cells(I, "L").Value Then
          'MsgBox "To date value should greater than From value", vbOKOnly
          'Exit Sub
          'End If
          'If Cells(I, "N").Value = "" Then
          'MsgBox "Please Enter Origin Country Code Value", vbOKOnly
          'Exit Sub
          'End If
          'If Cells(I, "O").Value = "" Then
          'MsgBox "Please Enter Point of Origin Location Code Value", vbOKOnly
          'Exit Sub
          'End If
          'If Cells(I, "R").Value = "" Then
          'MsgBox "Please Enter Port of Loading Code Value", vbOKOnly
          'Exit Sub
          'End If
          'If Cells(I, "S").Value = "" Then
          'MsgBox "Please Enter Origin Clearance Location Value", vbOKOnly
          'Exit Sub
          'End If
          'If Cells(I, "T").Value = "" Then
          'MsgBox "Please Enter Destination Clearance Location Value", vbOKOnly
          'Exit Sub
          'End If
          'If Cells(I, "U").Value = "" Then
          'MsgBox "Please Enter Port of Discharge Code Value", vbOKOnly
          'Exit Sub
          'End If
          If Cells(I, "Y").Value = "" Then
          MsgBox "Please Enter Consignee Final Destination Location Code Value", vbOKOnly
          Exit Sub
          End If
          If Cells(I, "Z").Value = "" Then
          MsgBox "Please Enter Destination Country Code Value", vbOKOnly
          Exit Sub
          End If
          If Cells(I, "AF").Value = "" Then
          MsgBox "Please Enter Active status Value", vbOKOnly
          Exit Sub
          End If
          If Cells(I, "AH").Value = "" Then
          MsgBox "Please Enter Carrier Allocation Number Value", vbOKOnly
          Exit Sub
          End If
          If Cells(I, "AI").Value = "" Then
          MsgBox "Please Enter  Carrier Allocation Valid From Date Value", vbOKOnly
          Exit Sub
          End If
          If Cells(I, "AJ").Value = "" Then
          MsgBox "Please Enter Carrier Nomination Sequence Number Value", vbOKOnly
          Exit Sub
          End If
          Next I
      End With
  
  End Sub
  </code></pre>