Color Code Cells VBA Macro

richmcgill

Board Regular
Joined
Feb 4, 2019
Messages
71
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?


DateLoan NumberCustomer Name Amount
5/19/201912345Smith $744.93
C
5/19/20193456Jones $ 784.89
5/19/20196789Johnson $ 333.43
<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> </tbody>
 

Excel Facts

Quick Sum
Select a range of cells. The total appears in bottom right of Excel screen. Right-click total to add Max, Min, Count, Average.
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,214,853
Messages
6,121,935
Members
449,056
Latest member
denissimo

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