Add text based on Cell Color

CJ_D

New Member
Joined
Mar 4, 2020
Messages
1
Office Version
  1. 365
Platform
  1. Windows
I need help with a macro. I need a macro that will put an "X" in either the "Pass" column or in the "Fail" column based to the color of the cells in columns C, D and E.

IE. If the color in Cell C.8 is green, put an X in the Pass column. If the color is red, put an X in the fail column.

1583338232340.png


Thank you in advance.

Using office 365. Windows
 

Excel Facts

Create a chart in one keystroke
Select the data and press Alt+F1 to insert a default chart. You can change the default chart to any chart type
Try this:
Assuming your cell colors are actually VbRed or VbGreen
This does not work if you cell color is determined by Conditional formatting.
And your post said:
based to the color of the cells in columns C, D and E.
you did not say what happens if c is red and D is green.
And must we check C D and E
This script only checks column C

VBA Code:
Sub Check_For_Color()
'Modified 3/4/2020 3:23:38 PM EST
Application.ScreenUpdating = False
Dim i As Long
Dim Lastrow As Long
Lastrow = Cells(Rows.Count, "C").End(xlUp).Row
For i = 8 To Lastrow
If Cells(i, "C").Interior.Color = vbGreen Then Cells(i, "G").Value = "X"
If Cells(i, "C").Interior.Color = vbRed Then Cells(i, "H").Value = "X"
Next
Application.ScreenUpdating = True
End Sub
 
Upvote 0
@My Aswer Is This
If you make this change to your code, it will handle CF colours as well
Rich (BB code):
Sub Check_For_Color()
'Modified 3/4/2020 3:23:38 PM EST
Application.ScreenUpdating = False
Dim i As Long
Dim Lastrow As Long
Lastrow = Cells(Rows.Count, "C").End(xlUp).Row
For i = 8 To Lastrow
If Cells(i, "C").DisplayFormat.Interior.Color = vbGreen Then Cells(i, "G").Value = "X"
If Cells(i, "C").DisplayFormat.Interior.Color = vbRed Then Cells(i, "H").Value = "X"
Next
Application.ScreenUpdating = True
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,968
Messages
6,122,509
Members
449,089
Latest member
RandomExceller01

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