Color Code Cells VBA Macro

richmcgill

Board Regular
Joined
Feb 4, 2019
Messages
87
Office Version
  1. 2016
Platform
  1. Windows
I heard that VBA / Macro could help me with color coding a range of cells based on adding a character to another cell.

In this case I am trying to clear an amount from a balance sheet.
If I add a C to clear the item I need the three cells to the left of the amount to color code yellow.
Can this be done and what would this macro look like?


[TABLE="width: 327"]
<colgroup><col width="69" style="width: 52pt; mso-width-source: userset; mso-width-alt: 2446;"> <col width="86" style="width: 65pt; mso-width-source: userset; mso-width-alt: 3072;"> <col width="103" style="width: 77pt; mso-width-source: userset; mso-width-alt: 3669;"> <col width="62" style="width: 47pt; mso-width-source: userset; mso-width-alt: 2218;"> <col width="57" style="width: 43pt; mso-width-source: userset; mso-width-alt: 2019;" span="2"> <tbody>[TR]
[TD="width: 69, bgcolor: transparent"]Date[/TD]
[TD="width: 86, bgcolor: transparent"]Loan Number[/TD]
[TD="width: 103, bgcolor: transparent"]Customer Name[/TD]
[TD="width: 62, bgcolor: transparent"] Amount [/TD]
[TD="width: 57, bgcolor: transparent"] [/TD]
[TD="width: 57, bgcolor: transparent"] [/TD]
[/TR]
[TR]
[TD="bgcolor: yellow, align: right"]5/19/2019[/TD]
[TD="bgcolor: yellow, align: right"]12345[/TD]
[TD="bgcolor: yellow"]Smith[/TD]
[TD="bgcolor: transparent"] $744.93
[/TD]
[TD="bgcolor: transparent"] C
[/TD]
[TD="bgcolor: transparent, align: right"][/TD]
[/TR]
[TR]
[TD="bgcolor: transparent, align: right"]5/19/2019[/TD]
[TD="bgcolor: transparent, align: right"]3456[/TD]
[TD="bgcolor: transparent"]Jones[/TD]
[TD="bgcolor: transparent"] $ 784.89 [/TD]
[TD="bgcolor: transparent"] [/TD]
[TD="bgcolor: transparent"]
[/TD]
[/TR]
[TR]
[TD="bgcolor: transparent, align: right"]5/19/2019[/TD]
[TD="bgcolor: transparent, align: right"]6789[/TD]
[TD="bgcolor: transparent"]Johnson[/TD]
[TD="bgcolor: transparent"] $ 333.43 [/TD]
[TD="bgcolor: transparent"] [/TD]
[TD="bgcolor: transparent"] [/TD]
[/TR]
</tbody>[/TABLE]
 

Excel Facts

Excel Can Read to You
Customize Quick Access Toolbar. From All Commands, add Speak Cells or Speak Cells on Enter to QAT. Select cells. Press Speak Cells.
As much as I like using VBA, you don't really need to here. A simple conditional formatting rule will do the trick.

Select the entire range of values in columns A-C, add the conditional formatting formula below, and add the yellow background format.

Code:
=$E2="C"
 
Upvote 0
But, if you really want VBA, here is one way to do it.

Code:
Sub HighC()
Dim r As Range: Set r = Range("E2:E" & Range("E" & Rows.Count).End(xlUp).Row)
Dim cel As Range

For Each cel In r
    If cel.Value = "C" Then
        Range("A" & cel.Row & ":C" & cel.Row).Interior.ColorIndex = 6
    End If
Next cel

End Sub
 
Upvote 0
But, if you really want VBA, here is one way to do it.

Code:
Sub HighC()
Dim r As Range: Set r = Range("E2:E" & Range("E" & Rows.Count).End(xlUp).Row)
Dim cel As Range

For Each cel In r
    If cel.Value = "C" Then
        Range("A" & cel.Row & ":C" & cel.Row).Interior.ColorIndex = 6
    End If
Next cel

End Sub
Another way to write this macro...
Code:
Sub HighC2()
  Intersect([A:C], [E:E].SpecialCells(xlConstants).EntireRow).Interior.Color = vbYellow
End Sub
 
Upvote 0
Thank you very much for the help.

I really do appreciate everyone taking the time to help.
 
Upvote 0
Thank you very much for the help.

I really do appreciate everyone taking the time to help.
 
Upvote 0

Forum statistics

Threads
1,224,820
Messages
6,181,159
Members
453,021
Latest member
Justyna P

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