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

Show numbers in thousands?
Use a custom number format of #,##0,K. Each comma after the final 0 will divide the displayed number by another thousand

Von Pookie

MrExcel MVP
Joined
Feb 17, 2002
Messages
13,686
You can use a Worksheet_SelectionChange event to do this. What are the ranges you want to use?
 

jbklee66

New Member
Joined
Sep 13, 2006
Messages
6
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
 

Joe4

MrExcel MVP, Junior Admin
Joined
Aug 1, 2002
Messages
58,423
Office Version
  1. 365
Platform
  1. Windows

ADVERTISEMENT

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
 

jbklee66

New Member
Joined
Sep 13, 2006
Messages
6
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
 

jbklee66

New Member
Joined
Sep 13, 2006
Messages
6

ADVERTISEMENT

Sorry cant get Html creator working
 

Joe4

MrExcel MVP, Junior Admin
Joined
Aug 1, 2002
Messages
58,423
Office Version
  1. 365
Platform
  1. Windows
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=
 

jbklee66

New Member
Joined
Sep 13, 2006
Messages
6
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
 

Forum statistics

Threads
1,137,330
Messages
5,680,857
Members
419,936
Latest member
rphill48

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
Top