Coloring Different Cells by Selecting Another Cell

Multi

New Member
Joined
Jan 21, 2005
Messages
3
I want to select a cell and have a different part of the sheet color in. Does anybody know how to do that?
 

Excel Facts

Can you sort left to right?
To sort left-to-right, use the Sort dialog box. Click Options. Choose "Sort left to right"
Can you supply some more information?

It sounds like you want either Conditional Formatting or to use code in a Worksheet event.
 
Upvote 0
It can be done, but you'll have to give some specifics.

What cells do you want colored when a cell is selected? Does the range and/or color depend on the selected cell?
 
Upvote 0
Thanks for your response. What I want to do is select a cell by clicking on it with my mouse. Then a different part of the document lights up. Something close to this effect is fine. Bold, highligh, buttons....whatever. The effect I am trying to represent is selecting a certain cell, then a different cell or two will light up.
Thanks for your help :)
 
Upvote 0
Possible solution:

1) On the Tools menu in Microsoft Excel, point to Macro, and then click Visual Basic Editor.
2) d-click on the ThisWorkbook object in the left hand window (looks like explorer tree)
3) Type or copy the code below into the right hand code window.
4) Post into window and close the VBE (File|Close)

Code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html><head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>VBAProject_Foglio1.htm</title>
<style type=text/css>
<!--
body {background-color: #ffffff; color: #000000; font-family: "Courier New"; font-size: 10pt}
.keyword {background-color: #ffffff; color: #000080}
.comment {background-color: #ffffff; color: #008000}
-->
</style>
</head>
<body>
<nobr>
<div> <span class="keyword">Private Sub</span> Worksheet_SelectionChange(<span class="keyword">ByVal</span> Target <span class="keyword">As</span> Range)</div>
<div> <span class="keyword">Dim</span> MyCellAddr <span class="keyword">As String</span>, DifferentPartAddr <span class="keyword">As String</span></div>
<div> </div>
<div> <span class="comment">'Insert the address of the cell you want to select (I suppose A1)</span></div>
<div>MyCellAddr = "$A$1"</div>
<div> <span class="comment">'Insert the address of the range you want to highlight (suppose B2:D4)</span></div>
<div>DifferentPartAddr = "B2:D4"</div>
<div> </div>
<div> <span class="keyword">If</span> Target.Address = MyCellAddr <span class="keyword">Then</span></div>
<div>    <span class="comment">'MyCell selected: apply format</span></div>
<div>    Range(DifferentPartAddr).Interior.ColorIndex = 35</div>
<div> <span class="keyword">Else</span></div>
<div>    Range(DifferentPartAddr).Interior.ColorIndex = xlNone</div>
<div> <span class="keyword">End If</span></div>
<div> <span class="keyword">End Sub</span></div>
</nobr>
</body></html>


Ciao
 
Upvote 0
:oops: :oops:

wrong step 2)

Substitute: 2) d-click on the ThisWorkbook object in the left hand window (looks like explorer tree)

with: 2) d-click on the Sheet1(Sheet1) object in the left hand window (looks like explorer tree)

P.S. I supposed you want to select a cell inSheet1

:p :p
 
Upvote 0
WOW, GREAT!!!
Thats exactly what I wanted. Now I just got to change it to represent the cells I wanted highlighted. Should not be a proble.
Thanks Again :D
 
Upvote 0

Forum statistics

Threads
1,214,522
Messages
6,120,022
Members
448,939
Latest member
Leon Leenders

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