Help with vba

jbklee66

New Member
Joined
Sep 13, 2006
Messages
6
Can someone help with code to change font colour of a range when a cell in the range is clicked

Ta
 

Excel Facts

Is there a shortcut key for strikethrough?
Ctrl+S is used for Save. Ctrl+5 is used for Strikethrough. Why Ctrl+5? When you use hashmarks to count |||| is 4, strike through to mean 5.
You can use a Worksheet_SelectionChange event to do this. What are the ranges you want to use?
 
Upvote 0
Something like that but a range like the one mentioned below


Sub Macro1()
Range("A2:G2").Select
With Selection.Font
.ColorIndex = 6
End With
End Sub
 
Upvote 0
Simply change the words "Interior" in Chip's code to "Font".

Do you want this to be a permament change or only while the range is selected? If permanent, delete the two rows indicated in the code below. Otherwise, use as is.
Code:
Private Sub Workbook_SheetSelectionChange(ByVal Sh As Object, ByVal Target As Range)

Static OldRange As Range
On Error Resume Next
Target.Font.ColorIndex = 6 ' yellow - change as needed
'For permanent change, delete the two rows below
OldRange.Font.ColorIndex = xlColorIndexNone
Set OldRange = Target

End Sub
 
Upvote 0
Thanks for replying

That works fine, but only on one cell at a time. I want the whole rows font to change colour when you activate any cell in the row. see table.

Private Sub Workbook_SheetSelectionChange(ByVal Sh As Object, ByVal Target As Range)

Static OldRange As Range
On Error Resume Next
Target.Font.ColorIndex = 6 ' yellow - change as needed
'For permanent change, delete the two rows below
OldRange.Font.ColorIndex = xlColorIndexNone
Set OldRange = Target

End Sub
 
Upvote 0
That works fine, but only on one cell at a time. I want the whole rows font to change colour when you activate any cell in the row. see table.
That's because that isn't what you asked for.
Can someone help with code to change font colour of a range when a cell in the range is clicked
It works on a whole range at a time (if you select mutliple cells, it will work on multiple cells).

If you want it to highlight the whole row of the activecell, then check out this variation which I helped someone else out with today:
http://www.mrexcel.com/board2/viewtopic.php?t=232737&highlight=
 
Upvote 0
The code is working on the whole workbook, can I limit it to one sheet. Also can I rechange colour back to black by same method.

Ta
 
Upvote 0

Forum statistics

Threads
1,213,490
Messages
6,113,957
Members
448,535
Latest member
alrossman

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