は、前の手順が満たされていない場合のテストにのみ行われることを意味します。また、もう少し物事をスピードアップします文をネスト
Set Col = Range("O2:O" & lastrowOU3)
For Each Cell In Col
If Cell.Offset(0, -2) = 0 And Cell.Offset(0, -1) = 0 Then
Cell.Value = "NEW ITEM"
ElseIf Cell.Offset(0, -2) = 0 And Cell.Offset(0, -1) = "NEW ITEM" Then
Cell.Value = "NOT VALIDATED"
ElseIf Cell.Offset(0, -2) < Date And Cell.Offset(0, -1) = "NEW ITEM" Then
Cell.Value = "NOT VALIDATED"
ElseIf Cell.Offset(0, -2) < Date And Cell.Offset(0, -1) = "VALIDATED" Then
Cell.Value = "NOT VALIDATED"
ElseIf Cell.Offset(0, -2) < Date And Cell.Offset(0, -1) = "NOT VALIDATED" Then
Cell.Value = "NOT VALIDATED 1"
ElseIf Cell.Offset(0, -2) < Date And Cell.Offset(0, -1) = "NOT VALIDATED 1" Then
Cell.Value = "NOT VALIDATED 2"
ElseIf Cell.Offset(0, -2) >= Date Then
Cell.Value = "VALIDATED"
End If
Next
:
Set Col = Range("O2:O" & lastrowOU3)
For Each Cell In Col
If Cell.Offset(0, -2) = 0 Then
IF And Cell.Offset(0, -1) = 0 Then
Cell.Value = "NEW ITEM"
ElseIf Cell.Offset(0, -1) = "NEW ITEM" Then
Cell.Value = "NOT VALIDATED"
End If
ElseIf Cell.Offset(0, -2) < Date Then
If Cell.Offset(0, -1) = "NEW ITEM" Then
Cell.Value = "NOT VALIDATED"
ElseIf Cell.Offset(0, -1) = "VALIDATED" Then
Cell.Value = "NOT VALIDATED"
ElseIf Cell.Offset(0, -1) = "NOT VALIDATED" Then
Cell.Value = "NOT VALIDATED 1"
ElseIf Cell.Offset(0, -1) = "NOT VALIDATED 1" Then
Cell.Value = "NOT VALIDATED 2"
End If
ElseIf Cell.Offset(0, -2) >= Date Then
Cell.Value = "VALIDATED"
End If
Next
をそして、それぞれの「Cell.Offset、おそらくもっとそれをスピードアップしますSELECT CASE文を使用するなど(0、x)を「一度だけ評価される必要があります(私は思う):
Set Col = Range("O2:O" & lastrowOU3)
For Each Cell In Col
Select Case Cell.Offset(0, -2)
Case 0
Select Case Cell.Offset(0, -1)
Case 0
Cell.Value = "NEW ITEM"
Case "NEW ITEM"
Cell.Value = "NOT VALIDATED"
Case Else
End Select
Case < Date
Select Case Cell.Offset(0, -1)
Case "NEW ITEM"
Cell.Value = "NOT VALIDATED"
Case "VALIDATED"
Cell.Value = "NOT VALIDATED"
Case "NOT VALIDATED"
Cell.Value = "NOT VALIDATED 1"
Case "NOT VALIDATED 1"
Cell.Value = "NOT VALIDATED 2"
Case Else
End Select
Case Else
Cell.Value = "VALIDATED"
End Select
Next
1.)IF/ELSEIF/ENDIF 2.)変数を変数に代入すると、ループごとに2回だけシートに移動します。 –
さらに速くしたい場合は、VBAの代わりにExcelの式を使用してください。 – Slai