我组成了突出显示所选行的代码。如果选择更改 - 新选中的行将突出显示,并且之前选择的格式将返回到初始状态。我用VBA突出显示所选行导致选择整行
- 列9作为高亮格式样品并作为基线为未选中的行的条件格式
- 排10。
该代码工作正常。但是,选中单元格后,该行将突出显示,所选单元格保持活动状态,但选中整行。有人可以帮助我取消选择除目标单元格外的所有内容吗?
here没有帮助。
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
LastRowA = Range("A" & Rows.Count).End(xlUp).Row
If Target.Cells.Count > 1 Or Target.Cells.Count < 1 Then 'If selected 1 cell
'Do nothing
Else
Application.ScreenUpdating = False
If Target.Row > 10 And Target.Row < LastRowA + 1 Then
Rows("10:10").Copy 'Restore all rows to custom conditional formatting of row 10
For tableRow = 11 To LastRowA
Rows(tableRow & ":" & tableRow).PasteSpecial Paste:=xlPasteFormats, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
Next tableRow
Rows("9:9").Copy 'Highlight active row using formating of row #9
Rows(Target.Row).PasteSpecial Paste:=xlPasteFormats, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
Application.CutCopyMode = False
Target.Cells.Activate 'Return Target to initially selected cell
End If
Application.ScreenUpdating = True
End If
End Sub
试着改变你的'行(Target.Row).PasteSpecial'为'细胞(Target.Row,Target.Column).PasteSpecial' – BruceWayne
@BruceWayne - 在这种情况下, ,那么只有一个单元格会粘贴格式。 –