If the cell input is above a certain value, color cell green (with multiple conditions)

Bona_Excel

New Member
Joined
Nov 19, 2021
Messages
2
Platform
  1. 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
 

Excel Facts

Add Bullets to Range
Select range. Press Ctrl+1. On Number tab, choose Custom. Type Alt+7 then space then @ sign (using 7 on numeric keypad)
Why using VBA when you can simply perform conditional formatting in excel.

Kindly share the sample data
 
Upvote 0

Forum statistics

Threads
1,214,945
Messages
6,122,393
Members
449,081
Latest member
JAMES KECULAH

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top