不得不延長我以前的潛艇。需要找到三個字串中的任何一個(錯誤,但存盤為文本)。如果找到,帶有警告的 msgbox 并停止子。如果沒有找到,請呼叫其他子程式。
以下是我到目前為止的代碼。問題是當找到字串時,我也會呼叫另一個子程式。
Sub Z_ZWR_sprawdzbledy()
Dim MyAr(1 To 3) As String
Dim ws As Worksheet
Dim aCell As Range, bCell As Range
Dim i As Long
Set ws = ThisWorkbook.Sheets("komunikat_OS_zwroty")
MyAr(1) = "#VALUE!"
MyAr(2) = "#N/A"
MyAr(3) = "#REF!"
With ws
'~~> Loop through the array
For i = LBound(MyAr) To UBound(MyAr)
Set aCell = Worksheets("komunikat_OS_zwroty").Cells.Find(What:=MyAr(i), LookIn:=xlValues, _
LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False)
If Not aCell Is Nothing Then
Set bCell = aCell
MsgBox "UWAGA! Znaleziono bledy!" & vbNewLine & vbNewLine & "SPRAWDZ KOMORKI Z #N/A!, #N/D! lub #REF!"
Else
End If
Next
Call zwrot2
End With
End Sub
uj5u.com熱心網友回復:
一種可能的解決方案。代碼回圈遍歷給定的范圍,如果出現錯誤,則會出現訊息并將變數“blnCheckErrors”設定為 true。
回圈完成后,if 陳述句將檢查“blnCheckErrors”。如果它是假的,那么給定的程序/子將被執行。
Sub Z_ZWR_sprawdzbledy()
Dim MyAr(1 To 3) As String
Dim ws As Worksheet
Dim aCell As Range, bCell As Range
Dim i As Long
Dim blnCheckErrors as boolean
Set ws = ThisWorkbook.Sheets("komunikat_OS_zwroty")
MyAr(1) = "#VALUE!"
MyAr(2) = "#N/A"
MyAr(3) = "#REF!"
With ws
'~~> Loop through the array
For i = LBound(MyAr) To UBound(MyAr)
'我稍微優化了這里的代碼,因為你確實使用了與上面相同的陳述句 (ThisWorkbook.Sheets("komunikat_OS_zwroty"))
Set aCell = .Cells.Find(What:=MyAr(i), LookIn:=xlValues, _
LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=False, SearchFormat:=False)
If Not aCell Is Nothing Then
Set bCell = aCell 'Edit: What is this for? It seems that you don't use it again
MsgBox "UWAGA! Znaleziono bledy!" & vbNewLine & vbNewLine & "SPRAWDZ KOMORKI Z #N/A!, #N/D! lub #REF!"
blnCheckErrors = true
End If
Next
'不再需要“呼叫”陳述句,只需使用子/函式的名稱
if blnCheckErrors = false then zwrot2
End With
End Sub
uj5u.com熱心網友回復:
從它的外觀來看,無論如何都會呼叫 zwrot2。您需要將 Call zwrot2 移動到 For 回圈中,然后(我猜)在 ELSE 之后的 IF 陳述句中。
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/391135.html
