I am currently trying to apply this code below to active sheets by converting it to macro. However I am having trouble with for each function.
This is the original code.
Sub Worksheet_SelectionChange(ByVal Target As Excel.Range)
'Update 20140318
Static xRow
Static xColumn
If xColumn <> "" Then
With Columns(xColumn).Interior
.ColorIndex = xlNone
End With
With Rows(xRow).Interior
.ColorIndex = xlNone
End With
End If
pRow = Selection.Row
pColumn = Selection.Column
xRow = pRow
xColumn = pColumn
With Columns(pColumn).Interior
.ColorIndex = 22
.Pattern = xlSolid
End With
With Rows(pRow).Interior
.ColorIndex = 6
.Pattern = xlSolid
End With
End Sub
My unsuccessful attempt to convert :
Sub Highlighter()
'
' Highlighter Macro
'
' Keyboard Shortcut: Ctrl+Shift+H
'
Dim xSheet As Worksheet
For Each xSheet In This.Workbook.Worksheets
xSheet.Select
Static xRow
Static xColumn
If xColumn <> "" Then
With Columns(xColumn).Interior
.ColorIndex = xlNone
End With
With Rows(xRow).Interior
.ColorIndex = xlNone
End With
End If
pRow = Selection.Row
pColumn = Selection.Column
xRow = pRow
xColumn = pColumn
With Columns(pColumn).Interior
.ColorIndex = 22
.Pattern = xlSolid
End With
With Rows(pRow).Interior
.ColorIndex = 6
.Pattern = xlSolid
Next xSheet
End Sub
Please help! Thanks!
Third attempt >> It is working but how to do Selection Change within workbook to apply to all sheets?
Sub Highlighter()
'
' Highlighter Macro
'
' Keyboard Shortcut: Ctrl+Shift+H
'
Dim xSheet As Worksheet
For Each xSheet In ActiveWorkbook.Worksheets
xSheet.Select
Static xRow
Static xColumn
If xColumn <> "" Then
With xSheet.Columns(xColumn).Interior
.ColorIndex = xlNone
End With
With xSheet.Rows(xRow).Interior
.ColorIndex = xlNone
End With
End If
pRow = Selection.Row
pColumn = Selection.Column
xRow = pRow
xColumn = pColumn
With xSheet.Columns(pColumn).Interior
.ColorIndex = 22
.Pattern = xlSolid
End With
With xSheet.Rows(pRow).Interior
.ColorIndex = 6
.Pattern = xlSolid
End With