Excel 宏编译错误 - 参数不可选

问题描述 投票:0回答:1

在 Excel 中运行 VBA 代码时收到错误消息。错误消息是编译错误,并显示消息“参数不可选”。我不知道代码哪里出错了。


Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
Cancel = True

If Not Intersect(Target, Union(Range("K15:K31"))) Is Nothing Then
If Target.Interior.ColorIndex = 43 Then
Target.Interior.ColorIndex = 0
ActiveCell.Value = ""
Else: Target.Interior.ColorIndex = 43
ActiveCell.Value = ChrW(&H2713)
ActiveCell.Font.ColorIndex = 2
End If
End If
End Sub

Private Sub Worksheet_BeforeRightClick(ByVal Target As Range, Cancel As Boolean)
Set Cancel = True

If Not Intersect(Target, Union(Range("K15:K31"))) Is Nothing Then
If Target.Interior.ColorIndex = 3 Then
Target.Interior.ColorIndex = 48
ActiveCell.Value = "N/A"
ElseIf Target.Interior.ColorIndex = 48 Then
Target.Interior.ColorIndex = 0
Else: Target.Interior.ColorIndex = 3
ActiveCell.Value = ChrW(&H2716)
ActiveCell.Font.ColorIndex = 2
End If
End If
End Sub

excel vba
1个回答
0
投票

Union
方法需要两个参数。在您的代码中使用此方法是不必要的。只需将其删除并仅使用
Range
对象即可。

If Not Intersect(Target, Range("K15:K31")) Is Nothing Then

© www.soinside.com 2019 - 2024. All rights reserved.