excel - VBA-双击将x添加到单元格,但如何双击删除?
问题描述
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
推荐阅读
- c - 如何使用/编译这个文件?
- python - Python subprocess.Popen 没有给我正确的 pid?
- r - 在 R 中提取相应的值
- python-3.x - 我在哪里可以获得有关 AWS 用户所做操作的活动日志
- python - 从函数内部创建的对象模拟方法调用(python)
- angular - 如何从“开始”停止 Ionic 4 App 直到它获得所有需要的数据
- hadoop - Hadoop start-all.sh 错误
- r - 如何重命名具有相同名称的列以使其不同?
- javascript - Javascript 记录敏感数据
- javascript - 清除自定义过滤器但无法重绘数据表