操作栏->数据->数据验证;设置设置如上图
下面程序只针对某个表,如Sheet1。
鼠标右击该表的名称(如Sheet1),选择“查看代码”,粘贴下列代码:
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Address = "$B$1" Then
If Cells(1, 2) <> "" Then
If Cells(1, 1) = "" Then
MsgBox "A1 不能为空" '此句可不要
Cells(1, 2) = ""
Cells(1, 2).Select
End If
End If
End If
End Sub