如果在双击时合并它们,则在excel VBA上标记单元格

时间:2017-07-18 09:01:22

标签: excel vba excel-vba

我在双击某些单元格时勾选复选标记。我的代码如下所示:

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

但是在Merged cellls AA-AK上它给了我一个错误

1 个答案:

答案 0 :(得分:0)

尝试这样......

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