【问题标题】:in all worksheets, on double click color cell在所有工作表中,双击颜色单元格
【发布时间】:2020-01-03 19:10:36
【问题描述】:

如何实现此代码以处理工作簿中的所有工作表。`

Option Explicit

Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
    Cancel = True
    If Not Intersect(Target, Me.Range("A2:A100")) Is Nothing Then
        Select Case Target.Interior.ColorIndex
            Case xlNone, 4: Target.Interior.ColorIndex = 45
            Case 45: Target.Interior.ColorIndex = 0
            Case Else: Target.Interior.ColorIndex = xlNone
        End Select
    End If
End Sub

`

【问题讨论】:

标签: excel vba colors double-click


【解决方案1】:

要实现这一点,您可以使用Workbook_SheetBeforeDoubleClick。代码如下:

Private Sub Workbook_SheetBeforeDoubleClick(ByVal Sh As Object, ByVal Target As Range, Cancel As Boolean)
    Cancel = True
    If Not Intersect(Target, Sh.Range("A2:A100")) Is Nothing Then
        Select Case Target.Interior.ColorIndex
            Case xlNone, 4: Target.Interior.ColorIndex = 45
            Case 45: Target.Interior.ColorIndex = 0
            Case Else: Target.Interior.ColorIndex = xlNone
        End Select
    End If
End Sub

希望这会有所帮助。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-10-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-07-20
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多