View Code - VBcolor

DPChristman

Board Regular
Joined
Sep 4, 2012
Messages
171
Office Version
  1. 365
Platform
  1. Windows
I have a spreadsheet (form,really) that contains a lot of automatically updated fields from other spreadsheets.

Because of all the activity in this document, I don't want to lock any cells.

However, to give my users the ability to identify the current active cell.

I found an used this Worksheet_SelectionChange event by right clicking the tab, selecting view code, and pasting this

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Application.ScreenUpdating = False
Cells.Interior.ColorIndex = 0
Target.Interior.Color = vbCyan
Application.ScreenUpdating = True
End Sub

It works as advertised, but for some reason, it leaves all the other previously shaded rows un-shaded.

Is there a way to just highlight only the active cell?

The above script is supposed to do it, but apparently not
 
Thanks Rick, I think this will work good for my needs.

I know that I saw basic color fill options. Is there a chart somewhere to show different shade variations (pale yellow vs bright yellow, etc.)?
 
Upvote 0

Excel Facts

Will the fill handle fill 1, 2, 3?
Yes! Type 1 in a cell. Hold down Ctrl while you drag the fill handle.
I know that I saw basic color fill options. Is there a chart somewhere to show different shade variations (pale yellow vs bright yellow, etc.)?
There are only eight predefined color constants in VB which can be assigned to the Color property ... vbBlack, vbRed, vbGreen, vbYellow, vbBlue, vbMagenta, vbCyan, vbWhite; otherwise you need to use the RGB function (which takes three color component arguments... the red, green and blue components, in that order). You can see sample colors and get the appropriate color components for that color like this... select any cell, right-click that cell and select "Format Cells..." from the popup menu that appears, then click the "Fill" tab on the dialog box that appears and then click the "More Colors..." button and then click the "Custom" tab on the next dialog box that appears.... select a "base" color on the right vertical color rectangle and the click around the colors square until you find a color you like in the "New" half of the smaller color square in the lower right corner, then use the Red, Green and Blue color values in the three scroll boxes for the Red, Green and Blue color components of the RGB function back in your code where you assign a color value to the Color property.
 
Upvote 0

Forum statistics

Threads
1,215,766
Messages
6,126,760
Members
449,336
Latest member
p17tootie

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