Temporary formatting of cell with focus

R

Ricter

How would one go about setting up a sheet where any cell with the focus would
have, say, a red background?
 
G

Gary''s Student

If by focus you mean select, then try this:


Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Cells.Interior.ColorIndex = xlNone
Target.Interior.ColorIndex = 46
End Sub

put this in worksheet code, not a standard module.
 
R

Ricter

That works, student of Gary, thanks. One more question, is there a pallet
somewhere I can look at to find those colorindexes? 46 is orange, on my
monitor anyway...

Ricter
 
G

Gary''s Student

I don't know. I usually turn on the Macro Recorder and then color a cell. I
look at the generated code to get the value.
 
G

Gord Dibben

Ricter

Copy this to a General Module and run it.

Sub ListColorIndexes()
Dim Ndx As Long
Sheets.Add
For Ndx = 1 To 56
Cells(Ndx, 1).Interior.ColorIndex = Ndx
Cells(Ndx, 2).Value = Hex(ThisWorkbook.Colors(Ndx))
Cells(Ndx, 3).Value = Ndx
Next Ndx
End Sub

Note: if you have modified any colors, you will see discrepancies.


Gord Dibben MS Excel MVP
 
Top