[英]MsgBox after not finding a value
我有一個運行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
下面的代碼將檢查您指定的范圍,如果找不到任何內容或具有匹配項的單元格的行號,則給您錯誤。
Dim FindResult As Object
n=... 'set whatever value you want to find
Range("AS3:AS50000").Select
Set FindResult = Selection.Find(n, LookIn:=xlFormulas, LookAt:=xlWhole)
If FindResult Is Nothing Then
MsgBox ("missing")
Else
MsgBox (FindResult.Row)
End If
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.