【问题标题】:Excel VBA: Cell color change on double clickExcel VBA:双击时单元格颜色变化
【发布时间】:2020-10-17 21:52:58
【问题描述】:

您可以在下面找到双击切换单元格颜色的代码,我需要使其仅适用于 D2:D14 范围内的单元格。目前这适用于所有单元格..

Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, cancel As Boolean)
cancel = True
Select Case Target.Interior.ColorIndex
    Case xlNone, 4: Target.Interior.ColorIndex = 6
    Case xlNone, 6: Target.Interior.ColorIndex = 3
    Case Else: Target.Interior.ColorIndex = 4
End Select
End Sub

请帮帮我!提前致谢!

【问题讨论】:

    标签: excel colors onclick cell


    【解决方案1】:

    使用Intersect

    Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
    
    If Intersect(Target, Range("D2:D14")) Is Nothing Then Exit Sub
    
    Cancel = True
    
    Select Case Target.Interior.ColorIndex
        Case xlNone, 4: Target.Interior.ColorIndex = 6
        Case xlNone, 6: Target.Interior.ColorIndex = 3
        Case Else: Target.Interior.ColorIndex = 4
    End Select
    
    End Sub
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-06-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多