May 20 2023 02:37 PM
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.
May 20 2023 03:05 PM
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.
May 20 2023 03:19 PM
May 20 2023 03:32 PM
May 20 2023 03:51 PM
May 21 2023 06:23 AM
May 21 2023 07:12 AM
May 21 2023 07:28 AM - edited May 21 2023 09:04 AM
Solution
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.
May 21 2023 07:48 AM
May 21 2023 07:28 AM - edited May 21 2023 09:04 AM
Solution
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.