在所有工作表中,双击颜色单元格

in all worksheets, on double click color cell

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

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

`

要实现它,您可以使用 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

希望对您有所帮助。