Format changed when the cell selected

F

Freshman

Dear experts,

I want when a cell is selected, the font of a value inside this cell will be
enlarged from point 10 to pont 12, the font colour will be changed from black
to bold white and the background colour will be changed to red. Can it be
done by a VBA code or any other ways? Please kindly advise.

Thanks in advance.
 
D

Dennis

Enter this into the visual basic editor for your worksheet. In my example
cell C9 is the one that changes when it is activated.

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Application.ActiveCell = Application.Range("C9") Then
Application.ActiveCell.Font.Size = 12
Application.ActiveCell.Font.Bold = True
Application.ActiveCell.Interior.ColorIndex = 3
Application.ActiveCell.Font.ColorIndex = 2
End If
End Sub
 
F

Freshman

Hi Dennis,

Thanks for your code and it works perfect. However, I'm sorry that I did not
ask my question clearly. I want to changed format can be restore to original
format if the cell is deselected afterwards. What additional codes should be
added? Please kindly advise. Sorry for trouble you on this.

Best regards.
 
D

Dennis

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Application.ActiveCell = Application.Range("C9") Then
Application.ActiveCell.Font.Size = 12
Application.ActiveCell.Font.Bold = True
Application.ActiveCell.Interior.ColorIndex = 3
Application.ActiveCell.Font.ColorIndex = 2
Else
Application.Range("C9").Font.Size = 10
Application.Range("C9").Font.Bold = False
Application.Range("C9").Interior.ColorIndex = 2
Application.Range("C9").Font.ColorIndex = 1
End If
End Sub
 
D

Dennis

Slight change to my last post to change the cell back again.

Application.Range("C9").Interior.ColorIndex = xlColorIndexNone
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top