2017-07-18 42 views
0

我在雙擊特定單元格時勾選複選標記。我的代碼如下所示:在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 

但在合併cellls AA-AK它給了我一個錯誤

+1

簡短的回答是不使用合併單元格。 – SJR

回答

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 
+0

或者在開頭簡單地添加'Set Target = Target.Cells(1)';) –

+0

是的,這也可以做到這一點,並且需要更少的打字。 :) – sktneer

+0

sktneer thanx工作 –

相關問題