Hi guys,
I found this VBA code (here: https://www.extendoffice.com/documents/excel/2129-excel-highlight-active-cell.html)
<code class="vb keyword">Sub</code> <code class="vb plain">Workbook_SheetSelectionChange(</code><code class="vb keyword">ByVal</code> <code class="vb plain">Sh </code><code class="vb keyword">As</code> <code class="vb keyword">Object</code><code class="vb plain">, </code><code class="vb keyword">ByVal</code> <code class="vb plain">Target </code><code class="vb keyword">As</code> <code class="vb plain">Excel.Range)</code>
<code class="vb comments">'Update 20140923</code>
<code class="vb keyword">Static</code> <code class="vb plain">xLastRng </code><code class="vb keyword">As</code> <code class="vb plain">Range</code>
<code class="vb keyword">On</code> <code class="vb keyword">Error</code> <code class="vb keyword">Resume</code> <code class="vb keyword">Next</code>
<code class="vb plain">Target.Interior.ColorIndex = 6</code>
<code class="vb plain">xLastRng.Interior.ColorIndex = xlColorIndexNone</code>
<code class="vb keyword">Set</code> <code class="vb plain">xLastRng = Target</code>
<code class="vb keyword">End</code> <code class="vb keyword">Sub</code>
It works great but if I have cells with the fill color different than white, it sets the fill color to white.
Is there a way to improve the code so that it restores, once I move to another cell, whatever fill color I have in the active cell or selection?
Thank you very much,
Matt
I found this VBA code (here: https://www.extendoffice.com/documents/excel/2129-excel-highlight-active-cell.html)
<code class="vb keyword">Sub</code> <code class="vb plain">Workbook_SheetSelectionChange(</code><code class="vb keyword">ByVal</code> <code class="vb plain">Sh </code><code class="vb keyword">As</code> <code class="vb keyword">Object</code><code class="vb plain">, </code><code class="vb keyword">ByVal</code> <code class="vb plain">Target </code><code class="vb keyword">As</code> <code class="vb plain">Excel.Range)</code>
<code class="vb comments">'Update 20140923</code>
<code class="vb keyword">Static</code> <code class="vb plain">xLastRng </code><code class="vb keyword">As</code> <code class="vb plain">Range</code>
<code class="vb keyword">On</code> <code class="vb keyword">Error</code> <code class="vb keyword">Resume</code> <code class="vb keyword">Next</code>
<code class="vb plain">Target.Interior.ColorIndex = 6</code>
<code class="vb plain">xLastRng.Interior.ColorIndex = xlColorIndexNone</code>
<code class="vb keyword">Set</code> <code class="vb plain">xLastRng = Target</code>
<code class="vb keyword">End</code> <code class="vb keyword">Sub</code>
It works great but if I have cells with the fill color different than white, it sets the fill color to white.
Is there a way to improve the code so that it restores, once I move to another cell, whatever fill color I have in the active cell or selection?
Thank you very much,
Matt
Last edited: