gpt4 book ai didi

excel - 突出显示选定的行和列

转载 作者:行者123 更新时间:2023-12-04 22:18:42 26 4
gpt4 key购买 nike

我有下面的代码。突出显示始终启用。我正在尝试找出如何创建一些东西以在我想要的时候启用/禁用。
提前致谢。

  Sub Worksheet_SelectionChange(ByVal Target As Excel.Range)
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 = 6
.Pattern = xlSolid
End With
With Rows(pRow).Interior
.ColorIndex = 6
.Pattern = xlSolid
End With
End Sub

最佳答案

尝试,

Private Sub Worksheet_SelectionChange(ByVal Target As Range)

Cells.Interior.Color = xlNone
If Range("a1") = "" Then Exit Sub 'Set operation according to a1 cell
With Target
.EntireRow.Interior.ColorIndex = 6
.EntireColumn.Interior.ColorIndex = 6
End With
End Sub
最好在工作表中插入 activeX 控件复选框并相应地设置行为。
enter image description here
Private Sub Worksheet_SelectionChange(ByVal Target As Range)

Cells.Interior.Color = xlNone
'If Range("a1") = "" Then Exit Sub
If CheckBox1 Then Exit Sub
With Target
.EntireRow.Interior.ColorIndex = 6
.EntireColumn.Interior.ColorIndex = 6
End With
End Sub

关于excel - 突出显示选定的行和列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66399731/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com