|
▼imori さん:
↑で悩んだことを取り入れてみて・・・
でも、そもそも、要件の理解が間違っている公算大で、自信度10%ぐらいですが・・・
Sub Test2()
Dim i As Long
Dim w As Variant
Dim maxlvl As Long
Dim oldlvl As Long
Dim curlvl As Long
Dim myExists As Boolean
Dim myHold As Boolean
Dim myNG As Boolean
Dim x As Long
maxlvl = WorksheetFunction.Max(Range("A2", Range("A" & Rows.Count).End(xlUp)))
oldlvl = maxlvl + 1
ReDim w(1 To maxlvl, 1 To 3)
For x = 1 To maxlvl
w(x, exists) = False
w(x, hold) = False
w(x, ng) = False
Next
For i = Range("A" & Rows.Count).End(xlUp).Row To 2 Step -1
curlvl = Cells(i, "A").Value
If curlvl > oldlvl Then
For x = curlvl To maxlvl
w(x, exists) = False
w(x, hold) = False
w(x, ng) = False
Next
End If
If IsEmpty(Cells(i, "C")) Then
myExists = False
myHold = False
myNG = False
If curlvl < maxlvl Then
For x = curlvl + 1 To maxlvl
If w(x, exists) Then myExists = True
If w(x, hold) Then myHold = True
If w(x, ng) Then myNG = True
Next
End If
If myNG Then
Cells(i, "C").Value = "NG"
ElseIf myHold Or Not myExists Then
Cells(i, "C").Value = "保留"
Else
Cells(i, "C").Value = "OK"
End If
End If
w(curlvl, exists) = True
If Cells(i, "C").Value = "保留" Then w(curlvl, hold) = True
If Cells(i, "C").Value = "NG" Then w(curlvl, ng) = True
oldlvl = curlvl
Next
End Sub
|
|