VBA code fail Auto highlight

Copper Contributor
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

@Laura Backshell 

Did you save the file as Macro-Enabled Workbook?

Point to remember is, only .xls or .xlsb or .xlsm file can hold the macro in it.

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.

@Laura Backshell 

Check the attached in which I have placed the code on Sheet1 Module, let me know if that works for you.

Make sure to enable the macros in the file when prompted. If macros are disabled, they won't work.

 

Hi

The code worked fine when I used your spreadsheet, but when I opened a new excel file and added the module it didn’t work.

How do I make it active in the spreadsheet? It’s Saved as macro-enabled before I added the code but it’s not highlighting the rows.

Thanks

@Laura Backshell 

This is selection change event code which gets triggered automatically when you change the selection on the sheet and it should be placed on the Sheet Module but not on a standard module like Module1.

To place the code on to the Sheet Module, right click on the Sheet Tab Name and choose View Code and then paste the code into the opened code window, save your file as Macro-Enabled Workbook.

 

The file I uploaded with the code would work each time you open it because the code was placed on the Sheet Module.

I want my headers to stay at top of page as scrolling down. How do I do that?