求助excel VBA实现,A1单元格必须输入内容,A2才能输入内容

2025-03-22 16:56:44
推荐回答(2个)
回答1:

操作栏->数据->数据验证;设置设置如上图

回答2:

下面程序只针对某个表,如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