簡體   English   中英

如果在雙擊時合並了Excel VBA上的單元格,則將它們標記為

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

我在某些單元格上雙擊時打上復選標記。 我的代碼如下所示:

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

但是在合並后的AA-AK細胞上卻給了我一個錯誤

像這樣嘗試...

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