A function question

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
 
J

Jason Morin

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
 
A

Alan Beban

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

Alan Beban
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top