Forum Discussion

LauraDaisy's avatar
LauraDaisy
Copper Contributor
Mar 11, 2020

VBA code fail Auto highlight

I entered code for auto fill which worked (copied and pasted from google)

I saved and closed but when I went to open it stopped working.

I now can’t apply the code to any spreadsheet.

How can I fix that? Code below:

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
On Error Resume Next
Application.ScreenUpdating = False
' Clear the color of all the cells
Cells.Interior.ColorIndex = 0
If Target.Cells.Count > 1 Then Exit Sub
With Target
' Highlight the entire row and column that contain the active cell
.EntireRow.Interior.ColorIndex = 6
.EntireColumn.Interior.ColorIndex = 6
End With
Application.ScreenUpdating = True
End Sub

6 Replies

  • Julieenos's avatar
    Julieenos
    Copper Contributor
    I want my headers to stay at top of page as scrolling down. How do I do that?
    • LauraDaisy's avatar
      LauraDaisy
      Copper Contributor
      Hi

      Yeah, even when I apply to a new file or save and open as xsl etc it still doesn’t apply. Saves the code fine but doesn’t make a difference.

Resources