0

I have a macro in my workbook that is tied to a hotkey which highlights all columns in the currently selected row. However, it only works if one row is selected. I cant think of a way to adjust it to highlight all the rows if multiple are selected. Here is the code that I am currently using.

Sub highlight_done()
'
' highlight_done Macro
'
' Keyboard Shortcut: Ctrl+q
'

Dim r As Long
    r = ActiveCell.Row
    
    Range("A" & r & ":Y" & r).Select
    With Selection.Interior
        .Pattern = xlSolid
        .PatternColorIndex = xlAutomatic
        .Color = 12611584
        .TintAndShade = 0
        .PatternTintAndShade = 0
    End With
    With Selection.Font
        .Color = vbWhite
        .TintAndShade = 0
    End With

End Sub

Any help would be appreciated.

1 Answer 1

2

Perhaps like the following, using Intersect and Selection.EntireRow to get the range to be colored:

Sub highlight_done()
'
' highlight_done Macro
'
' Keyboard Shortcut: Ctrl+q
'

    If Not TypeOf Selection Is Range Then Exit Sub
    
    Dim rng As Range
    Set rng = Intersect(Selection.EntireRow, Range("A:Y"))
    
    With rng.Interior
        .Pattern = xlSolid
        .PatternColorIndex = xlAutomatic
        .Color = 12611584
        .TintAndShade = 0
        .PatternTintAndShade = 0
    End With
    With rng.Font
        .Color = vbWhite
        .TintAndShade = 0
    End With

End Sub
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.