【发布时间】:2019-02-02 17:48:30
【问题描述】:
我有一个运行 InputBox 的宏,用户在其中键入数字,然后 excel 在特定范围内找到一个包含该值的单元格。我想创建一个MsgBox,如果找不到给定的数字,它会发出警报,然后再次运行InputBox,直到值在范围内。
我有点想法该怎么做,但无法使发现本身起作用。我已经录制了一个宏,但是如果它没有找到任何东西,我不知道如何正确设置它。
到目前为止我的代码:
Sub leftbutton()
Start: n = InputBox("Podaj numer punktu z wykresu") 'give me a point number from a chart
If n = "" Then Exit Sub
If n = "0" Then
MsgBox ("Liczba musi byc wieksza od zera") 'number must be > 0
GoTo Start
End If
If Not IsNumeric(n) Then
MsgBox ("Podaj liczbe!") 'give me a number!
GoTo Start
End If
Range("AS3:AS50000").Select
if
Selection.Find(What:=n, After:=ActiveCell, LookIn:=xlFormulas, _
LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase _
:=False, SearchFormat:=False).Activate 'now how to know if it finds value or not?
Then msgbox("Nie ma takiego punktu na wykresie") 'there's no such point on a chart
Goto Start
Else '~> select cell with the found value
End If
End Sub
【问题讨论】: