vba 如何在Excel中突出显示行和列

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4107270/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-11 12:16:30  来源:igfitidea点击:

how to highlight row & column in Excel

excelvba

提问by Martin08

How can I use VBA or conditional formatting to highlight the entire current row and column of the current cell? Thank you.

如何使用 VBA 或条件格式突出显示当前单元格的整个当前行和列?谢谢你。

回答by Lance Roberts

Here's one way:

这是一种方法:

ActiveSheet.Rows(ActiveCell.Row).Interior.Color = RGB(r, g, b)
ActiveSheet.Columns(ActiveCell.Column).Interior.Color = RGB(r, g, b)

You can fill in r,g & b to achieve the highlighting color you want.

您可以填写 r,g & b 以实现您想要的突出显示颜色。

回答by Fink

In your sheets worksheets selection change event, you can use something like this:

在您的工作表工作表选择更改事件中,您可以使用以下内容:

Private Sub Worksheet_SelectionChange(ByVal Target As Range)

    Const HIGHLIGHT_COLOR As Long = 4

    'remove past colors
    ActiveSheet.Cells.Interior.ColorIndex = xlNone

    With Me
        .Columns(Target.Column).Interior.ColorIndex = HIGHLIGHT_COLOR
        .Rows(Target.Row).Interior.ColorIndex = HIGHLIGHT_COLOR
    End With
End Sub