我编写了一段代码,突出显示选定的行。如果选择更改-新选定的行将被高亮显示,并且前面的选择的格式返回到初始的。我使用
密码很好用。但是,当单元格被选中时,行将被高亮显示,所选单元格保持活动状态,但整个行将被选中。有人能帮我取消除目标单元以外的所有东西吗?
来自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发布于 2015-12-21 19:58:45
尝尝这个
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim LastRowA As Long
Dim tableRow As Long
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
Application.EnableEvents = False
Target.Cells.Select
Application.EnableEvents = True
End If
Application.ScreenUpdating = True
End If
End Subhttps://stackoverflow.com/questions/34403033
复制相似问题