Dim RowNum As Integer, num As Integer
num = 7
ActiveSheet.Select
Range(Cells.Find("X-bar").Offset(1, 0), Cells.Find("X-bar").Offset(1, 0).End(xlDown)).Select
RowNum = Selection.CountLarge
For i = 1 To (RowNum - 1)
If Cells(i, 1).Value < Cells(i + 1, 1).Value Then
k = k + 1
'Sheets("sheet2").Cells(i, 1).Value = k
If k > num Then
MsgBox "樣本呈遞增現象", , "製程異常"
k = 0
End If
ElseIf Cells(i, 1).Value > Cells(i + 1, 1).Value Then
k = k + 1
'Sheets("sheet2").Cells(i, 1).Value = k
If k > num Then
MsgBox "樣本呈遞減現象", , "製程異常"
k = 0
End If
Else
k = 0
End If
Next
End Sub
[attach]7572[/attach]
感謝您耐心的閱讀 m(-_-)m作者: kimbal 時間: 2011-8-25 00:32
就是有任何MSGBOX出現就停止檢查?
最簡單的話可以在MSGBOX後加上EXIT SUB
'目前是num總數>7,而非連續7個num
Sub WrongTrend()
Dim RowNum As Integer, num As Integer
num = 7
ActiveSheet.Select
Range(Cells(1, 1), Cells(1, 1).End(xlDown)).Select
RowNum = Selection.CountLarge
For i = 1 To (RowNum - 1)
If Cells(i, 1).Value < Cells(i + 1, 1).Value Then
k = k + 1
'Sheets("sheet2").Cells(i, 1).Value = k
If k > num Then
MsgBox "樣本呈遞增現象", , "製程異常"
k = 0
Exit Sub
End If
ElseIf Cells(i, 1).Value > Cells(i + 1, 1).Value Then
k = k + 1
'Sheets("sheet2").Cells(i, 1).Value = k
If k > num Then
MsgBox "樣本呈遞減現象", , "製程異常"
k = 0
Exit Sub
End If
Else
k = 0
End If
Next作者: smooth131 時間: 2011-8-25 22:19