【发布时间】:2016-11-24 19:44:17
【问题描述】:
我有两个范围 A1:A4 和 A5:A10。我希望能够在从第一个范围说 A1 双击时突出显示一个单元格,然后当我双击同一范围内的一个单元格说 A2 时,这将取消突出显示 A1 并突出显示 A2。我想对第二个范围做同样的事情,但彼此独立,所以我最终会得到 2 个突出显示的单元格,一个来自每个范围。我目前使用的代码目前只对第二个范围执行此操作:
Public PreviousCell As Range
Public PreviousCell2 As Range
Private Sub Worksheet_BeforeDoubleClick(ByVal target As Range, Cancel As Boolean)
If Not PreviousCell Is Nothing Then PreviousCell.Interior.ColorIndex = xlNone
With target.Interior
If Not .ColorIndex = xlNone Then
.ColorIndex = xlNone
ElseIf Not Intersect(target, Range("A1:A4")) Is Nothing Then
.ColorIndex = 15
ElseIf Not .ColorIndex = 15 Then
.ColorIndex = xlNone
End If
End With
Cancel = True
Set PreviousCell = target
If Not PreviousCell2 Is Nothing Then PreviousCell2.Interior.ColorIndex = xlNone
With target.Interior
If Not .ColorIndex = xlNone Then
.ColorIndex = xlNone
ElseIf Not Intersect(target, Range("A5:A10")) Is Nothing Then
.ColorIndex = 15
ElseIf Not .ColorIndex = 15 Then
.ColorIndex = xlNone
End If
End With
Cancel = True
Set PreviousCell2 = target
End Sub
谢谢!
【问题讨论】: