【问题标题】:Excel Macro to Highlight All Columns in Selected RowsExcel 宏突出显示选定行中的所有列
【发布时间】:2020-06-26 21:24:40
【问题描述】:

我的工作簿中有一个宏,它与一个热键相关联,该热键突出显示当前选定行中的所有列。但是,它仅在选择一行时才有效。如果选择了多个,我想不出一种方法来调整它以突出显示所有行。这是我目前正在使用的代码。

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

任何帮助将不胜感激。

【问题讨论】:

    标签: excel vba


    【解决方案1】:

    可能像下面这样,使用IntersectSelection.EntireRow 来获取要着色的范围:

    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
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2022-12-12
      • 2014-02-11
      • 1970-01-01
      • 1970-01-01
      • 2014-12-28
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多