I have created this code that successfully performs the task that I want. However, I got it to work only for the first row, "E5" just to see if it worked.
This code checks if each ID is within the maximum allowable range, using the data in columns E5 and V5 in the dataset.
Sub TestII()
Dim Sheet As Worksheet
Dim cell As Range
Dim lr As Long
Dim i As Integer
If (Range("E5") = "462266446" And Range("V5") < 3.75) Then
MsgBox "Good"
ElseIf (Range("E5") = "89008P588" And Range("V5") < 3.75) Then
MsgBox "Good"
ElseIf (Range("E5") = "89008P638" And Range("V5") < 4.5) Then
MsgBox "Good"
Else
MsgBox "Bad"
End If
End Sub
-------------------------------------------------------------------------------------------------------------------------------------------------------------------
How do I do this through the entire used range though?
I attempted to use the code below to perform the task through each row, but to highlight the violations instead of message boxes, but it doesn't quite work.
What should I change in order to perform a successful loop?
Thanks
---------------------------------------------------------------------------------------------------------------------------------------------------------------------
Sub Test()
Dim lr As Long
Dim WS As Worksheet
Dim r As Long
lr = Cells(Rows.Count, "C").End(xlUp).Row
For r = 5 To lr
If (Columns(5).Cells(r).Value = "462266446" And Columns(22).Cells(r).Value > 3.75) Then
Rows(5).Interior.ColorIndex = 3
ElseIf (Columns(5).Cells(r).Value = "89008P588" And Columns(22).Cells(r).Value > 3.75) Then
Rows(5).Interior.ColorIndex = 3
ElseIf (Columns(5).Cells(r).Value = "89008P638" And Columns(22).Cells(r).Value > 4.5) Then
Rows(5).Interior.ColorIndex = 3
Else
MsgBox "No Violations"
End If
Next r
End Sub
This code checks if each ID is within the maximum allowable range, using the data in columns E5 and V5 in the dataset.
Sub TestII()
Dim Sheet As Worksheet
Dim cell As Range
Dim lr As Long
Dim i As Integer
If (Range("E5") = "462266446" And Range("V5") < 3.75) Then
MsgBox "Good"
ElseIf (Range("E5") = "89008P588" And Range("V5") < 3.75) Then
MsgBox "Good"
ElseIf (Range("E5") = "89008P638" And Range("V5") < 4.5) Then
MsgBox "Good"
Else
MsgBox "Bad"
End If
End Sub
-------------------------------------------------------------------------------------------------------------------------------------------------------------------
How do I do this through the entire used range though?
I attempted to use the code below to perform the task through each row, but to highlight the violations instead of message boxes, but it doesn't quite work.
What should I change in order to perform a successful loop?
Thanks
---------------------------------------------------------------------------------------------------------------------------------------------------------------------
Sub Test()
Dim lr As Long
Dim WS As Worksheet
Dim r As Long
lr = Cells(Rows.Count, "C").End(xlUp).Row
For r = 5 To lr
If (Columns(5).Cells(r).Value = "462266446" And Columns(22).Cells(r).Value > 3.75) Then
Rows(5).Interior.ColorIndex = 3
ElseIf (Columns(5).Cells(r).Value = "89008P588" And Columns(22).Cells(r).Value > 3.75) Then
Rows(5).Interior.ColorIndex = 3
ElseIf (Columns(5).Cells(r).Value = "89008P638" And Columns(22).Cells(r).Value > 4.5) Then
Rows(5).Interior.ColorIndex = 3
Else
MsgBox "No Violations"
End If
Next r
End Sub