Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
Dim rInt As Range
Dim rCell As Range
Set rInt = Intersect(Target, Range("B3:CS71"))
If Not rInt Is Nothing Then
For Each rCell In rInt
rCell.Value = "x"
Next
End If
Set rInt = Nothing
Set rCell = Nothing
Cancel = True
End Sub
我找到了一些示例代码,但它们似乎非常适合这种情况,并专注于值,我无法操作这些代码,但只是看看是否有其他人看到过";双击可添加x,双击可删除x";,以及我如何应用";删除";部分在这里。
提前谢谢。
只需在循环中添加一个If
语句。试试这个:
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
Dim rInt As Range
Dim rCell As Range
Set rInt = Intersect(Target, Range("B3:CS71"))
If Not rInt Is Nothing Then
For Each rCell In rInt
If rCell.Value = "" then
rCell.Value = "x"
Else
rCell.Value = ""
End If
Next
End If
Set rInt = Nothing
Set rCell = Nothing
Cancel = True
End Sub