PDA

View Full Version : Selected Cell Color / Personal.xlsb



grichey
06-04-2009, 07:57 AM
Hello,

I am trying to add the following to personal.xlsb to change the color of selected cells. I have put it in a module in personal.xlsb in the correct folder but nothing seems to be happening.

What am I missing here?

Thanks for the help.
Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Cells.FormatConditions.Delete
With Target
.FormatConditions.Add Type:=xlExpression, Formula1:="TRUE"
.FormatConditions(1).Interior.ColorIndex = 3 'Red
End With
End Sub

Simon Lloyd
06-04-2009, 02:32 PM
Hello,

I am trying to add the following to personal.xlsb to change the color of selected cells. I have put it in a module in personal.xlsb in the correct folder but nothing seems to be happening.

What am I missing here?

Thanks for the help.
Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Cells.FormatConditions.Delete
With Target
.FormatConditions.Add Type:=xlExpression, Formula1:="TRUE"
.FormatConditions(1).Interior.ColorIndex = 3 'Red
End With
End Sub
Wouldn't this work better?Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Cells.Interior.ColorIndex = xlNone
With Target
.Interior.ColorIndex = 3
End With
End Sub

grichey
06-04-2009, 02:38 PM
Ya.. should do the same thing. How do I get it to actually work on excel starting though? I've saved it to module1 in my personal.xlsb and it prompts me when i exit, do you want to save blah blah this macro will be available the next time you start excel.

When I start excel though, it just highlights the same way as normal.

mdmackillop
06-04-2009, 03:10 PM
I don't believe you can do this with code in Personal. If you save the file as a template called Book.xltm in the Xlstart folder, it will open with this macro in it and highlight the cell on selection.


'In ThisWorkBook module
Private Sub Workbook_SheetSelectionChange(ByVal Sh As Object, ByVal Target As Range)
Cells.Interior.ColorIndex = xlNone
With Target
.Interior.ColorIndex = 3
End With
End Sub