简体   繁体   English

如果在双击时合并了Excel VBA上的单元格,则将它们标记为

[英]Mark cells on excel VBA if they are merged when double clicked

I am puuting a check mark on double click on certain cells. 我在某些单元格上双击时打上复选标记。 My code looks like this : 我的代码如下所示:

Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
If Not Intersect(Target, Range("AA38:AK48,M32:M40,M42:M52,M54:M69")) Is Nothing Then
  Cancel = True
  If VarType(Target.Value) = vbBoolean Then
    Target.Value = Not (Target.Value)
  Else
    Target.Value = IIf(Target.Value = "ü", Null, "ü")
  End If
End If
End Sub

But on the Merged cellls AA-AK it gives me an error 但是在合并后的AA-AK细胞上却给了我一个错误

Try it like this... 像这样尝试...

Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
If Not Intersect(Target, Range("AA38:AK48,M32:M40,M42:M52,M54:M69")) Is Nothing Then
  Cancel = True
  If VarType(Target.Cells(1).Value) = vbBoolean Then
    Target.Cells(1).Value = Not (Target.Cells(1).Value)
  Else
    Target.Cells(1).Value = IIf(Target.Cells(1).Value = "ü", Null, "ü")
  End If
End If
End Sub

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM