code that changes font color of column A and Row 1 upon selection

omairhe

Well-known Member
Joined
Mar 26, 2009
Messages
2,026
Office Version
  1. 2019
Platform
  1. Windows
Hey excel gurus,

I want to know how to change the font in column A and Row 1 of the selected column and selected row respectively.

The following is a code that would highlight the entire selected column and row,

Code:
Private Sub Workbook_SheetSelectionChange(ByVal Sh As Object, ByVal Target As Range)
'Update 20140318
Static xRow
Static xColumn
If xColumn <> "" Then
    With Columns(xColumn).Interior
        .ColorIndex = xlNone
    End With
    With Rows(xRow).Interior
        .ColorIndex = xlNone
    End With
End If
pRow = Selection.Row
pColumn = Selection.Column
xRow = pRow
xColumn = pColumn
With Columns(pColumn).Interior
    .ColorIndex = 20
    .Pattern = xlSolid
End With
With Rows(pRow).Interior
    .ColorIndex = 22
    .Pattern = xlSolid
End With
End Sub


instead the column A and row 1 font's color are required to be changed into green, and back to black when selection moves away.

Thank you for any help.
will appreciate a lot.
 

Excel Facts

Did you know Excel offers Filter by Selection?
Add the AutoFilter icon to the Quick Access Toolbar. Select a cell containing Apple, click AutoFilter, and you will get all rows with Apple

mumps

Well-known Member
Joined
Apr 11, 2012
Messages
11,727
Office Version
  1. 2013
  2. 2010
Platform
  1. Windows
See if this does what you want.
Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    ActiveSheet.Cells.Interior.ColorIndex = xlNone
    With Cells(Selection.Row, 1).Interior
        .ColorIndex = 22
        .Pattern = xlSolid
    End With
    With Cells(1, Selection.Column).Interior
        .ColorIndex = 20
        .Pattern = xlSolid
    End With
End Sub
 
Last edited:
Master Excel Bundle

Excel contains over 450 functions, with more added every year. That’s a huge number, so where should you start? Right here with this bundle.

Forum statistics

Threads
1,164,303
Messages
5,836,520
Members
430,437
Latest member
Emilycr

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