Bona_Excel
New Member
- Joined
- Nov 19, 2021
- Messages
- 2
- Platform
- Windows
I'm new to coding, but i have an excel map with a list of attributes of employees. Now i got the task to create an excel map, that, if the cells value are above a certain value, the cell is colored green. My code works fine if i only have one condition, but with three conditions it doesn't seem to work.
VBA Code:
Sub MA_Check()
For Each Column1 In Range("E3:E6").Columns
For Each cell1 In Column1.Cells
For Each Column2 In Range("O3:O6").Columns
For Each cell2 In Column2.Cells
For Each Column4 In Range("Q3:Q6").Columns
For Each cell4 In Column4.Cells
If cell1.Value <> cell2.Value Then
cell2.Interior.ColorIndex = 10
Else
cell2.Interior.ColorIndex = 3
End If
Next
Next
Next
Next
Next
Next
For Each Column1 In Range("E3:E6").Columns
For Each cell1 In Column1.Cells
For Each Column2 In Range("O3:O6").Columns
For Each cell2 In Column2.Cells
If cell1.Value = cell2.Value Then
cell2.Interior.ColorIndex = 10
Else
cell2.Interior.ColorIndex = 3
End If
Next
Next
Next
Next
For Each Column4 In Range("Q3:Q6").Columns
For Each cell4 In Column4.Cells
If cell4.Value >= 2 Then
cell4.Interior.ColorIndex = 10
Else
cell4.Interior.ColorIndex = 3
End If
Next
Next
For Each column3 In Range("P3:P6").Columns
For Each cell3 In column3.Cells
If cell3.Value >= 2 Then
cell3.Interior.ColorIndex = 10
Else
cell3.Interior.ColorIndex = 3
End If
Next
Next
End Sub