I have a fairly simple question regarding Excel and VBA, but because I'm new to VBA, I have no idea how to implement it.
I have an entire column full of a color code. The cells in that column say either R, G, or Y.
I need a macro that will traverse that column, change all cells that say "R" to have a fill of red, change all cells that say "Y" to have a fill of yellow, and change all cells that say "G" to have a fill of green.
I know this can also be done by simply sorting the rows alphabetically and then changing the colors manually, but I am looking for an automatic way of doing that.
Just use conditional formatting. You can change both the text and the cell to be the same colour
Highlight the column with your R, Y, and G and apply conditional formatting. | Home tab > Conditional Formatting > Highlight Cell Rules > Equal to... | Enter your letter of choice and select the corresponding color scheme!
Please try this:
Range("A1").Interior.Color = RGB(0, 0, 0)`
For R = 0 To 255
For G=0 To 255
For B=0 to 255
Cells(1 , 1).Interior.Color = RGB(R, G, B)`
Next R
You can use another loop change Cells row and column.
Related
I don’t want to use conditional formatting because I need a different value as the text in the cell (not what the color values apply to).
Column E is status (at risk/on track/needs improvement)
Column I is trend, displayed as arrows (Unicode text)
Column J is blank
I would like the color of the corresponding cells to be based on Column E text “Needs Improvement” in red, “At Risk” in yellow, and “On Track” in green.
So - in J2 through J13, I need the color only from the E2:E13 status and the trend arrows from I2:I13
I know this has been asked before in one way or another, but I can’t figure out the conditional formatting in VBA for some reason. Im sorry
Conditional formatting doesn’t work, I was trying to pull conditional colors from column E, but the only code I could get to work couldn’t integrate conditional formatting colors (it had to be true cell colors)
Below are the 4 sets of conditional formatting I used to accomplish the below example. I did not know what your trend data looks like so you'll need to adjust that to fit. To note, the formula in column J is ["=I" & row], so it's pulling over the same values. Those are hidden with the icon formatting. ::
Where RG = range("J2:J18")
Colour:="Red" while [=$E2="At Risk"]
Colour:="Yellow" while [=$E2="Needs Improvement"]
Colour:="Green" while [=$E2="On Track"]
Shape:="Icon Set" [checkmark] Show Icon Only
Example of formatting:
Example of result:
Let me know if any of that doesn't make sense.
I have a range of cell (A5: Z50).
A, C, E, G, H cell colour was set to "Light Blue" (Done).
The user will need to make changes or input new data into the remaining cell as and when required.
I want the cells (except the above) to change to "Light Green" (I managed to use Conditional Formatting to set it) when data are input/keyed in.
and When a comment is added, I want the cell colour to change to "Light Red".
How can I achieve this?
Managed to add a function and applied the conditional format to my worksheet.
This will help in solving 2 Conditional Format set.
Cell colour will be changed to Green when Text keyed in.
Cell colour will be changed to Another Colour when comments added.
Function IsComm(CellComm As Range) As Boolean
Application.Volatile
IsComm = False
If Not CellComm.Comment Is Nothing Then IsComm = True
End Function
The conditional formatting options works well to identify duplicates. How could I use the detected duplicates to write a value to a separate column? 1 for duplicate, 0 for not a duplicate. I thought I could use a VBA function based on the cell colour. Excel however does not store the dup detected cell color in the normal cell color property.
Note: 99 is not the light red color number, it's just for reference.
Function LightRed(rng As Range) As Boolean
If rng.Interior.ColorIndex = 99 Then
LightRed = 0
Else
LightRed = 1
End If
End Function
As tigeravatar said, you can use
=--(COUNTIF(A:A,A1)>1)
to detect duplicates and then you can apply a condition formatting on Column B where if cell value = 1, change background color to red
I want a macro that search in a column and find coincidences with the other column the fill it with yellow to recongnize it.
Column A 1137 Rows
Colimn B 537 Rows
Fill with yelllow in A the values found in B
I thinks its like
For i = 1 To i = 1137
For n = 1 To n = 592
If Cells(A, i) = Cells(L, n) Then
Cells(i, A).Value = Fill
End If
Next
Next
Why not use conditional formatting instead of a macro? Picture's worth more than my typing...
Original post didn't have a negative result so I added one.
You can do this VERY easily with conditional formatting!
Just select all of column A where you want the data to be highlighted and, then:
Select Conditional Formatting
New Rule
Use a Formula to determine which cell to format
Put in the following conditional format rule:
=ISNUMBER(MATCH($A1,$B$1:$B$537,0))
Set the fill color to yellow
And that should do it!
I have a range of cells with conditional formatting where if the cell exceeds a certain threshold value, it will be filled with red (I believe it is .color = 255).
I'm trying to create a macro that will search for cells in that range that exceed the threshold by searching for cells with .color = 255. The macro isn't working for some reason. It is unable to see that the cells are red due to conditional formatting. It can detect cells that I simply change the fill as red manually, though.
Sub macro22()
For Each m In Range("D7:L33")
If m.Interior.Color = 255 Then
ex = "exceedance"
End If
Next
Range("p22").Value = ex
End Sub
I know it is .color = 255 because if I record a macro to change the fill color of a cell to match the color I want from conditional formatting, that is the value it comes up with.
Color function doesn't return the colour if it's applied through conditional formatting. See here for alternative approaches
In case you have only one rule for CF you should check m.FormatConditions(0).Interior.Color value instead of m.Interior.Color - as more detailed response above)
0 represents the number of CF rules but starts from 0 (at least should be referenced so).