matching cell color based on cells above

sashazaliz

New Member
Joined
Nov 9, 2009
Messages
46
I'm trying to match the exact cell colors in a specific named range of cells to the adjacent cells 18 rows below. I thought the following code would certainly work but when I recalculate the worksheet the cells below don't change colors to match the ones above. What's wrong exactly? Please help!

Private Sub Worksheet_Calculate()
Dim cell As Range
For Each cell In Me.Range("color")
cell.Offset(18, 0).Interior.ColorIndex = _
cell.Interior.ColorIndex
Next
End Sub
 

Excel Facts

Add Bullets to Range
Select range. Press Ctrl+1. On Number tab, choose Custom. Type Alt+7 then space then @ sign (using 7 on numeric keypad)
Hello,

Try:



<font face=Courier New><SPAN style="color:#00007F">Private</SPAN> <SPAN style="color:#00007F">Sub</SPAN> Worksheet_Calculate()<br><SPAN style="color:#00007F">Dim</SPAN> cell <SPAN style="color:#00007F">As</SPAN> Range<br><br>    <SPAN style="color:#00007F">For</SPAN> <SPAN style="color:#00007F">Each</SPAN> cell <SPAN style="color:#00007F">In</SPAN> Range("color")<br>    cell.Offset(18, 0).Interior.ColorIndex = _<br>    cell.Interior.ColorIndex<br>    <SPAN style="color:#00007F">Next</SPAN><br><SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">Sub</SPAN></FONT>
 
Upvote 0
thanks for replying. For some reason the cells still don't change color after I press F9 to recalculate the sheet. any ideas on why this might be?
 
Upvote 0
Not sure,

It also doesn't when I try the same.

Type =1+1 into any cell and press enter.

It should work then.

I also noticed some colors were slightly off,

try this instead:

<font face=Courier New><SPAN style="color:#00007F">Private</SPAN> <SPAN style="color:#00007F">Sub</SPAN> Worksheet_Calculate()<br><SPAN style="color:#00007F">Dim</SPAN> cell <SPAN style="color:#00007F">As</SPAN> Range<br><br>    <SPAN style="color:#00007F">For</SPAN> <SPAN style="color:#00007F">Each</SPAN> cell <SPAN style="color:#00007F">In</SPAN> Range("color")<br>    cell.Offset(18, 0).Interior.Color = _<br>    cell.Interior.Color<br>    <SPAN style="color:#00007F">Next</SPAN><br><SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">Sub</SPAN></FONT>
 
Upvote 0
Glad to help!


If you have any trouble with the colors not being exact, try the code in post number 4.

-Jeff
 
Upvote 0
yes I'm using the latter code since it's imperative the colors are an exact match. again, thank you for your help. really appreciate it
 
Upvote 0

Forum statistics

Threads
1,224,592
Messages
6,179,789
Members
452,942
Latest member
VijayNewtoExcel

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