Forum Discussion
LauraDaisy
Mar 11, 2020Copper Contributor
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
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
- JulieenosCopper ContributorI want my headers to stay at top of page as scrolling down. How do I do that?
- Subodh_Tiwari_sktneerSilver Contributor
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.
- LauraDaisyCopper ContributorHi
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.- Subodh_Tiwari_sktneerSilver Contributor
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.