我想解决以下测试问题。如果单元格中存在错误,即(= 1/0),则之后不会运行其他测试。我想知道如何在测试主要任务部分中解决这个问题。
Private Sub ts_NoBlank(TsCn, STST, LsSt, LsIn, TsRw, MsCo, MsIC, MsSt)
Dim TsCl, StRw, LsRw, TsSh
TsCl = ColNrOfField(TsCn)
StRw = FsRwOfField(TsCn) + 1
LsRw = LsRwOfField(TsCn)
TsSh = SheetOfField(TsCn)
' Setting up Status Updates
PLcSt = -1 'Starting previous local status is set to -100% to show eitherways
rws = LsRw - StRw
'this part has to be copied to whenever showing the status (Value of LcSt has to be added each time by function)
LcSt = 0
If LcSt - PLcSt >= LsIn Then
Call ShowStatus(MsSt & " (" & Application.WorksheetFunction.Text(LcSt, "0%") & ")", ThisWorkbook.Worksheets("Calculations Running").Range("Started"), STST + (LsSt - STST) * LcSt)
PLcSt = LcSt
End If
' Testing primary task
ErrNr = 0
For Rw = StRw To LsRw 'ToDo speed up with fromrow torow
If Len(ThisWorkbook.Sheets(TsSh).Cells(Rw, TsCl)) = 0 Then
ThisWorkbook.Sheets(TsSh).Cells(Rw, TsCl).Interior.ColorIndex = 46
ErrNr = ErrNr + 1
End If
'Showing Local Status
LcSt = 0.1 + ((Rw / LsRw) * 0.75)
If LcSt - PLcSt >= LsIn Then
Call ShowStatus(MsSt & " (" & Application.WorksheetFunction.Text(LcSt, "0%") & ")", ThisWorkbook.Worksheets("Calculations Running").Range("Started"), STST + (LsSt - STST) * LcSt)
PLcSt = LcSt
End If
Next Rw
' Updating Test Results on 'Testing' Page
TRRg = "test" & TsRw & "_results"
If ErrNr = 0 Then 'If Results are Positive
ThisWorkbook.Worksheets("Testing").Range(TRRg) = MsCo
ThisWorkbook.Worksheets("Testing").Range(TRRg).Interior.ColorIndex = 51
Else 'If Errors are found
ErrMS = NumberizeMessage(MsIC, "SP_textvers", "S_textvers", "P_textvers", ErrNr)
ThisWorkbook.Worksheets("Testing").Range(TRRg) = ErrMS
ThisWorkbook.Worksheets("Testing").Range(TRRg).Interior.ColorIndex = 3
End If
'Showing Local Status
LcSt = 0.1
If LcSt - PLcSt >= LsIn Then
Call ShowStatus(MsSt & " (" & Application.WorksheetFunction.Text(LcSt, "0%") & ")", ThisWorkbook.Worksheets("Calculations Running").Range("Started"), STST + (LsSt - STST) * LcSt)
PLcSt = LcSt
End If
' Highlighting erroneous cells (if not done during testing)
If ErrNr > 0 Then
End If
'Showing Local Status 100%
LcSt = 1
If LcSt - PLcSt >= LsIn Then
Call ShowStatus(MsSt & " (" & Application.WorksheetFunction.Text(LcSt, "0%") & ")", ThisWorkbook.Worksheets("Calculations Running").Range("Started"), STST + (LsSt - STST) * LcSt)
PLcSt = LcSt
End If
End Sub
答案 0 :(得分:0)
既然您指出' Testing primary task
部分似乎有效,但在此之后似乎没有执行任何内容,我建议您到达此处时:
'Showing Local Status
LcSt = 0.1
If LcSt - PLcSt >= LsIn Then
此条件为false,因此代码永远不会执行。
然后你到了这里:
' Highlighting erroneous cells (if not done during testing)
If ErrNr > 0 Then
End If
并且没有代码可以执行,无论ErrNr
的值是什么。
然后你到了这里:
'Showing Local Status 100%
LcSt = 1
If LcSt - PLcSt >= LsIn Then
并且它仍在评估False
,所以它再也不会执行。
您是否经历过调试器以查看值并确保一切都符合您的预期?