Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Cell Colours - Can this be done 1

Status
Not open for further replies.

ZOR

Technical User
Jan 30, 2002
2,963
GB
If I were to manually select a particular cell back colour, could I put code behind another selected cell and say whatever cell D1 back colour is being used then make this cell back colour the same? Hope thats not confusing. Thanks
 


Hi,

Take a look at Condotional Formatting.

Skip,
[sub]
[glasses] [red]Be Advised![/red] Coeds studying ancient Egyptian plumbing, might be known as...
Pharaoh Faucet Majors [tongue][/sub]
 
Right click on worksheet tab.
Click view code.
Add the following to the Worksheet SelectionChange event:
If Target.Column = 2 Then
Target.Cells(1, 3).Interior.ColorIndex = Target.Cells.Interior.ColorIndex
End If
Now when you click on a cell in Column B the background color of the cell in Column D changes to match the cell in Column B.
 
Thanks Skip/Ben. I have looked at conditional formatting, but I am trying to find a way to reference what the fillcolor is in one cell and propogate that color to other cells within workpages that get referenced to. In other words not by any value, just cell references xxx = fillcolor of YYY.

Ben, I tried putting your code in, it worked once, I think after opening and closing the code window, but after changing the cell color of the master cell to another color, entering a change in the other cell did not change its color to that of the master cell. I tried putting the code in the change event, but still nothing. I must say I know nothing much about Excel, so appreciate the help. Thanks.
 
Thanks Ben, I went back to it and realised it works if you click the cell. I will wake up soon. Can one make reference to drill down the requested code to other sheets/pages? Thanks
 
What you could do is create a Name for all of the cells involved. You would select the cells, go to Insert, Name, Define, code below assumes name is CellsToMatchD1. For non-contiguous selecting you hold down Ctrl before clicking on the cell. The disadvantage of doing it this way is you will need to make sure it refers to the right cells anytime you add or delete columns/rows.
Following code should replace prior code (it now only works after selecting Cell D1):
If Target.Column = 1 And Target.Row = 4 Then
ActiveWorkbook.Names("CellsToMatchD1").RefersToRange.Cells.Interior.ColorIndex = Target.Cells.Interior.ColorIndex
End If
 
Sorry, but in order to reference D1 that first line of code should have been:
If Target.Column = 4 And Target.Row = 1 Then
 
Thats fine thanks Ben. Have a star for getting me off the ground. Will try out further. Thanks again.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top