Toggle highlight on for Specific cells Macro

时间:2018-09-18 20:06:42

标签: excel-vba

So I have a spreadsheet that I want a button where when I click it E4:S4 are highlighted and when it is clicked a second time E4:S4 are unhighlighted.

Here is what I have:

Sub Macro7()
'
' Macro7 Macro
'

'
    Range("E4:S4").Select

    With Selection.Interior.Color = 65535

    End With
    If Selection.Interior.Color = 65535 Then
        Selection.Interior.Pattern = xlNone
    End If
End Sub

1 个答案:

答案 0 :(得分:1)

Sub Macro7()
'
' Macro7 Macro
'

'


    With ActiveSheet.Range("E4:S4")    
        If .Interior.Color = 65535 Then
            .Interior.Color = xlNone
        Else
            .Interior.Color = 65535
        End If
    End With

End Sub