我有一张excel表和一个特定区域。这个区域可以
范围(" A1:A5")例如只需接受 0和1.它必须自动打开一个Inputbox / em>当用户输入0时(仅点击按钮或类似的东西)。当然在那一刻。
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Address.Value = 0 Then 'open InputBox
End If
End Sub
有这个,但这不起作用。
谢谢大家。
答案 0 :(得分:0)
Private Sub Worksheet_Change(ByVal Target As Range)
Dim rng As Range
Dim valueEnter As Long, lastRow As Long
Set rng = Range("A1:A5") 'specify your range here
lastRow = Cells(Rows.Count, "B").End(xlUp).Row
If Intersect(Target, rng) Is Nothing Or Target.Value <> 0 Then Exit Sub
valueEnter = InputBox("Gebe die ein:", "Eingabe")
If valueEnter >= 0 Then
Range("B" & lastRow + 1) = valueEnter
End If
End Sub
修改:___________________________________________________________ 强>
Private Sub Worksheet_Change(ByVal Target As Range)
Application.EnableEvents = False
Dim rng As Range
Dim valueEnter As Variant, lastRow As Long
Set rng = Range("A1:A5") 'specify your range here
lastRow = Cells(Rows.Count, "B").End(xlUp).Row
If Intersect(Target, rng) Is Nothing Or Target.Value <> 0 Then GoTo Jump
valueEnter = InputBox("Gebe die ein:", "Eingabe", 1)
If IsNumeric(valueEnter) Then
If valueEnter > 0 Then
Range("B" & lastRow + 1) = CInt(valueEnter)
Target.Value = ""
End If
Else
Target.Value = ""
End If
Jump:
Application.EnableEvents = True
End Sub