VBA Needed for Color Coding A cell based on the cell to the left of it

nrguerrieri

New Member
Joined
May 10, 2018
Messages
39
Office Version
  1. 365
I need a vba code that will color code the cell based on the cell to the left of it, previously cell (this is a table with say jan 2010 and the cell to the right will be feb 2010 and so forth)

For ex.

A1 and A2 can be any #. So for example A1 says -.79% and A2 says 0.75%. Since A1 to A2 was an increase. the cell in A2 will need to be green (>10% so a2 will need to be dark green - i explain further below)

Rules: The move from jan to feb (a1 to a2) increases It needs to be green (showing an increase). Vice versa, if the cell in a1 is more than a2, A2 needs to autofill color to red. Important to note that the code needs to be written that it is based on only the left adjacent, to the left of it because i need to replicate this in 100 other columns.

More rules. If its green and the increase is less than 10% of the value to the left = light green. If the cell to the right increased more than 10% than the left cell = dark green. Vice Versa as well. If the decrease was not more than 10% a light red, if the decrease was more than a 10% decrease = a darker red
+ if the cell moved either an increase or decrease of more than 50% please make it so there is no autofill = white

See pic for understanding


**Once you create the code I will be able to tailor (in the future) the colors i need and the difference parameters should i feel like changing the rules from like 50% to like 40% for example.
 

Attachments

  • Screen Shot 2020-03-28 at 5.50.27 PM.png
    Screen Shot 2020-03-28 at 5.50.27 PM.png
    113.7 KB · Views: 9

Excel Facts

Using Function Arguments with nested formulas
If writing INDEX in Func. Arguments, type MATCH(. Use the mouse to click inside MATCH in the formula bar. Dialog switches to MATCH.
I think you can just use conditional formats.
A lot simpler than writing VBA code for this.

Your conditional format checks run from high to low (or vice versa) and you stop if a condition is true. See example below.

Capture.PNG
 
Upvote 0
Thanks for the reply.. but is it based on the cell to the left of each continuing cell? If I do it this way.. Wont i need to enter this in for evert two set of cells. That would means i would have to do this over 200 times?

Thanks,
 
Upvote 0
No, you don't have to enter this for every cell pair.
So one way to do this, is to select the entire set of cells that need the conditional format. Then add the conditional formats one by one (keep the cells selected). As you can see in my example, the formula does not use absolute ($) cell references. The formula is I23>H23 and not $I$23>$H$23. Using relative references make the conditional format formula adjust for each cell in the row.
The other way, is to set the conditional formats up for the first cell in the row (in the same way as above) and then just copy / paste formats to the rest of the cells

Just play around with it a bit. You'd be impressed what you can do with conditional formats. I use them a lot.
 
Upvote 0

Forum statistics

Threads
1,214,653
Messages
6,120,751
Members
448,989
Latest member
mariah3

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