SOLVED

Highlight row and column when cell is selected

Brass Contributor

Hi,

 

Just need a little help to try out coding a sheet where the selected row and column automatically highlights.

 

I could perhaps do it using conditional formatting but I would like to try it out using VBA 

 

Thank you in advance for any help you can offer.

 

 

9 Replies

@packie 

Right-click the sheet tab.

Select View Code from the context menu.

Copy the following code into the worksheet module:

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    Dim MyColor As Long
    MyColor = RGB(224, 255, 224) ' a light green - change as desired
    Application.ScreenUpdating = False
    ' Clear the color of all the cells
    Cells.Interior.ColorIndex = xlColorIndexNone
    With ActiveCell
        ' Highlight the entire row and column that contain the active cell
        .EntireRow.Interior.Color = MyColor
        .EntireColumn.Interior.Color = MyColor
    End With
    Application.ScreenUpdating = True
End Sub

Warning: This will remove all existing fill color from the entire sheet before highlighting the row and column of the active cell!

This will apply to that specific sheet only.

It's possible to create a variant that will apply to all sheets in the workbook.

"Warning: This will remove all existing fill color from the entire sheet before highlighting the row and column of the active cell!"

I have fill color on the sheet which I do not want to loose using conditional formatting.

@packie 

Conditional formatting will not be affected.

Directly applied fill colors will be removed.

good to know, thanks
I will respond soon to let you know how I got on. Getting late here 🙂

@packie 

 

try this add-in

 

 

video

https://v.douyin.com/UkoXE3C

I am getting an error, something simple I'm sure

I've commented out all the code so it can be inspected

https://1drv.ms/x/s!Ai3wejactZJ_ljpDlt2z-9dunNG1?e=sqqJgH
best response confirmed by packie (Brass Contributor)
Solution

@packie 

 

There is no code whatsoever in that workbook. Perhaps you copied the code to a module in another workbook?

Here is the workbook with the code. You may have to unblock the file after downloading it.

Oops, not sure what happened
All's good now
Thankyou
1 best response

Accepted Solutions
best response confirmed by packie (Brass Contributor)
Solution

@packie 

 

There is no code whatsoever in that workbook. Perhaps you copied the code to a module in another workbook?

Here is the workbook with the code. You may have to unblock the file after downloading it.

View solution in original post