help in VB for cell values changing in rows & columns w/result in

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

The value in F is either less than 10 or greater than 10. Value is a
variable date in columns D, G & E.

If Col F result is 10 or more, and G2 is >= D2, THEN COMPLIANT
If Col F result is 10 or more, and G2 is < D2, THEN NONCOMPLIANT
If Col F result is <10, and E3 is >= D3, THEN COMPLIANT
If Col F result is <10, and E3 is < D3, THEN NONCOMPLIANT
 
Sub AABBCC()
Dim rngF as Range, rngG as Range, rngD as Range
Dim rngD1 as Range, rngE as Range
Dim i as Long
For i = 2 To 202
Set rngF = Cells(i, "F")
Set rngG = Cells(i, "G")
Set rngD = Cells(i, "D")
Set rngD1 = Cells(i + 1, "D")
Set rngE = Cells(i + 1, "E")

If rngF > 10 And rngG >= rngD Then
res = "COMPLIANT"
ElseIf (rngF > 10 And rngG < rngD) Then
res = "NONCOMPLIANT"
ElseIf (rngF < 10 And rngE >= rngD1) Then
res = "COMPLIANT"
ElseIf (rngF < 10 And rngE < rngD1) Then
res = "NONCOMPLIANT"
Else
res = "anomaly"
End If
MsgBox "row: " & i & " result: " & res
Next

End Sub
 
Missed the change in criteria

Sub AABBCC()
Dim rngF as Range, rngG as Range, rngD as Range
Dim rngD1 as Range, rngE as Range
Dim i as Long

Set rngG = Cells(2, "G")
Set rngD = Cells(2, "D")
Set rngD1 = Cells(3, "D")
Set rngE = Cells(3, "E")

For i = 4 To 204
Set rngF = Cells(i, "F")

If rngF >= 10 And rngG >= rngD Then
res = "COMPLIANT"
ElseIf (rngF >= 10 And rngG < rngD) Then
res = "NONCOMPLIANT"
ElseIf (rngF < 10 And rngE >= rngD1) Then
res = "COMPLIANT"
ElseIf (rngF < 10 And rngE < rngD1) Then
res = "NONCOMPLIANT"
Else
res = "anomaly"
End If
MsgBox "row: " & i & " result: " & res
Next

End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top