我写了以下代码:
Dim myValue As Variant
Dim myValue2 As Variant
Dim myValue3 As Variant
Dim myValue4 As Variant
On Error GoTo ErrorOccured
If Target.Address = "$B$10" And Target.Value = "Yes" Then
myValue = InputBox("Insert initialDate1")
myValue2 = InputBox("Insert initialDate2")
Range("C10").Value = myValue
Range("D10").Value = myValue2
End If
If Target.Address = "$B$12" And Target.Value = "Yes" Then
myValue3 = InputBox("InitialDate3")
myValue4 = InputBox("InitialDate4")
Range("C12").Value = myValue3
Range("D12").Value = myValue4
End If
ErrorOccured:
'Do when value is not valid
End Sub
其目的如下: 如果我从下拉列表中选择是,代码必须要求我填写第一个事件的开始和结束日期然后 它应该转到第二个事件,再次从下拉列表中选择是,并询问开始和日期。我的问题是我不知道如何连接这两个条件,以便它们保持独立。我不能使用And Or,Else或其他经典连接器。我应该可以为第一个事件选择“是”并输入日期,对于第二个事件结束,选择“否”,不会出现弹出窗口。当我只为一个事件编写代码时它起作用了
Private Sub Worksheet_Change(ByVal Target As Range)
Dim myValue As Variant
Dim myValue2 As Variant
On Error GoTo ErrorOccured
If Target.Address = "$B$10" And Target.Value = "Yes" Then
myValue = InputBox("Insert initialDate1")
myValue2 = InputBox("Insert initialDate2")
Range("C10").Value = myValue
Range("D10").Value = myValue2
End If
ErrorOccured:
End Sub
拜托,你能帮我这个吗?