change color if cell value is different from cell above

gd1sum8nfg2

New Member
Joined
Aug 30, 2014
Messages
6
Hello,
I'm looking for some VBA interior.color help. I have a column, with different values. What I want to happen is that, for instance, I have column with with say 15 rows worth of data. Say these values do not deviate, very much, from row to row. I want a vba code to set the interior color of the target cell to a color, whether red, blue, green, if the target cell is different than the one above it. So if, all in column "A", rows 1,2,3,4 are all "1" and then row "5" is 2, I want only row 5 to turn a different color. and if row 6 is also "2" then no color change. Thanks in advance!

P.S. so far my code looks something like this.

if target.column = 1 then
if target.cell<> target.offset (0,1) then
target.cell.interior.color= vbgreen
end if
end if
end sub
 

Excel Facts

Do you hate GETPIVOTDATA?
Prevent GETPIVOTDATA. Select inside a PivotTable. In the Analyze tab of the ribbon, open the dropown next to Options and turn it off
Try this

Code:
Private Sub Change_clr()
Dim cl as Range

For Each cl in Range("A2:A"& Range("A"&Rows.count).End(xlup).Row)  'Adjust "A" to suit the actual column
If cl <> cl.offset(0,1) then cl.Interior.Color = vbGreen
Next
End sub
 
Upvote 0

Forum statistics

Threads
1,226,719
Messages
6,192,668
Members
453,744
Latest member
luis javier

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