Hello everyone!
I have a small piece of code that will be used to compare a column (D) with the values of columns A B and C. It will later compare the column E with B and C.
One of the objectives is to compare each cell from D and E with the correspondent cells in A B and C. Example:
If D1 is < A1 + B1 and > A1 + C1, then the color comes in black, else it comes in red
If E1 is between B1 and C1, color comes in black, else comes in red.
I got the code working and to run each line and changing the colors. My main concern starts here. Every day i'll need to add 2 more columns and repeat the process. Ex: If F and G were added, in F column i would need to repeat the process in D (the values stay the same - as in, a b and c). Same goes for G (same as E).
Overall, i need the code to loop for the most columns up until it shows no values.
This is the code i have at the moment
I'd appreciate every suggestion
Thank you so much!!
I have a small piece of code that will be used to compare a column (D) with the values of columns A B and C. It will later compare the column E with B and C.
One of the objectives is to compare each cell from D and E with the correspondent cells in A B and C. Example:
If D1 is < A1 + B1 and > A1 + C1, then the color comes in black, else it comes in red
If E1 is between B1 and C1, color comes in black, else comes in red.
I got the code working and to run each line and changing the colors. My main concern starts here. Every day i'll need to add 2 more columns and repeat the process. Ex: If F and G were added, in F column i would need to repeat the process in D (the values stay the same - as in, a b and c). Same goes for G (same as E).
Overall, i need the code to loop for the most columns up until it shows no values.
This is the code i have at the moment
Code:
Sub ComparacaoTolerancias()
Dim i As Long
Dim j As Long
Dim lastrow As Long
Dim ws As Worksheet
Set ws = Folha1
For i = 1 To 500000
If IsEmpty(ws.Range("D" & i)) Then
Exit For
End If
If ws.Range("D" & i).Value <= ws.Range("A" & i).Value + ws.Range("B" & i).Value And ws.Range("D" & i).Value >= ws.Range("A" & i) + ws.Range("C" & i).Value Then
ws.Range("D" & i).Font.Color = vblack
Else: ws.Range("D" & i).Font.Color = vbRed
End If
If ws.Range("E" & i).Value <= ws.Range("B" & i).Value And ws.Range("E" & i).Value >= ws.Range("C" & i).Value Then
ws.Range("E" & i).Font.Color = vblack
Else: ws.Range("E" & i).Font.Color = vbRed
End If
Next i
MsgBox ("End")
End Sub
I'd appreciate every suggestion
Thank you so much!!