A function question

  • Thread starter Thread starter Marianne
  • Start date Start date
M

Marianne

Is there a function or some validation procedeure that
will prompt for data input and post an error message if a
cell is left blank when an adjacent cell equals a specific
text string?

Ex: A1 is "Cash", B1 will require data entry and give
error message "must enter name". If A1 is anything other
than "Cash", B1 may be left blank.

Thank You,
Marianne
 
Probably not the most efficient and definitely ugly, but
you could use this macro:

Private Sub Worksheet_Change(ByVal Target As Excel.Range)
If Target.Count > 1 Then Exit Sub
If Range("A1").Value = "Cash" And _
Len(Range("B1").Value) = 0 Then
Application.EnableEvents = False
MsgBox "Please Enter Name in B1"
If Target <> Range("A1") Then
Target.ClearContents
Range("B1").Select
End If
Application.EnableEvents = True
End If
If Range("A1").Value <> "Cash" Then
Range("B1").ClearContents
End If
End Sub


Right-click on the worksheet tab, View Code, and paste the
macro above into the VBE window.

HTH
Jason
Atlanta, GA
 
In B1, formatted with bold red font,
=IF(A1="Cash","!#must enter name","")

Alan Beban
 
Back
Top