OzGrid

How to highlight selected cell in row 1 only

< Back to Search results

 Category: [Excel]  Demo Available 

How to highlight selected cell in row 1 only

 

Requirement:

 

The user has a code which highlights the selected cell, this currently applies for the whole sheet, but the user wants it to apply in Row 1.


Eg: If the user clicks on any cell in row 1 the user wants it to highlight & if the user clicks on any other cell in the sheet, do nothing


This is the code that the user is using:

Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Application.ScreenUpdating = False
' Clear the color of all the cells
Cells.Interior.ColorIndex = 0
' Highlight the active cell
Target.Interior.ColorIndex = 8
Application.ScreenUpdating = True
End Sub

 

Solution:

 

Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Target.Row <> 1 Then Exit Sub
Application.ScreenUpdating = False
  ' Clear the color of all the cells
  Cells.Interior.ColorIndex = 0
  ' Highlight the active cell
  Target.Interior.ColorIndex = 8
Application.ScreenUpdating = True
End Sub

 

Obtained from the OzGrid Help Forum.

Solution provided by Carim.

 

See also: Index to Excel VBA Code and Index to Excel Freebies and Lesson 1 - Excel Fundamentals and Index to how to… providing a range of solutions and Index to new resources and reference sheets

 

See also:

How to copy entire row - keeping formulas
How to use VBA to turn columns into rows
How to delete last row
How to use a macro for grouping rows based on cells with same names
How to use a macro to pull every Nth row of data

 

Click here to visit our Free 24/7 Excel/VBA Help Forum where there are thousands of posts you can get information from, or you can join the Forum and post your own questions.

 


Gallery



stars (0 Reviews)