2

此代码在 C 列中放置复选标记或 X,并将字体更改为 Marlett:

Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)

    If Not Intersect(Target, Range("B5:B25", "D5:D25")) Is Nothing Then

     Cancel = True 'Prevent going into Edit Mode

        Target.Font.Name = "Marlett"

        If Target = vbNullString Then

           Target = "a"

        Else

           Target = vbNullString

        End If

    End If


End Sub
Private Sub Worksheet_BeforeRightClick(ByVal Target As Range, Cancel As Boolean)

If Not Intersect(Target, Range("B5:B25", "D5:D25")) Is Nothing Then

     Cancel = True 'Prevent going into Edit Mode

        Target.Font.Name = "Marlett"

        If Target = vbNullString Then

           Target = "r"

        Else

           Target = vbNullString

        End If

    End If

End Sub
4

1 回答 1

2

如果您在“立即”窗口中键入此内容(请参阅屏幕截图)

?Range("B5:B25", "D5:D25").Address

然后你会看到地址是$B$5:$D$25,因此它会这样做。如果您不想C被包括在内,请替换

Range("B5:B25", "D5:D25")

Range("B5:B25,D5:D25")

在此处输入图像描述

于 2013-02-19T16:07:37.780 回答