I am trying to create a VBA code which allows me to allocate background colors to a cell based on its difference with the neigbouring cell to the left.
Allow me to explain: http://imgur.com/UUfaFRA
When you look at the image above you can see:
C3
is red because it's value is higher thanB3
.C4
has no color as it's value is equal toB4
C5
is green because it's value is lower thanB5
I tried to put this into a VBA code but don't succeed:
Sheets("x").Range("C3").FormulaR1C1 =
"=IF(RC>RC[-1],Interior.ColorIndex = 3,IF(RC<RC[-1,Interior.ColorIndex= 4))"
another attempt was by recording an IF function:
If Sheets("x").Range("C3") > Sheets("x").Range("D3") Then
Sheets("x").Range("C3").Interior.ColorIndex = 3
I'm hoping someone could point me in the right direction as I'm (clearly) no VBA guru.
This piece of code works. there were some range issues which originaly resulted in a failure of this code.
Thank for your support!