简体   繁体   English

编译错误:参数不是可选的

[英]Compile error: Argument not optional

The below code lies in one of the sheets - I mean that it is not in a module, but in Sheet1 which is "Microsoft Excel Object". 下面的代码位于表单之一中-我的意思是它不在模块中,而是在Sheet1 ,即“ Microsoft Excel对象”。
I keep getting the following error: 我不断收到以下错误:

Compile error: Argument not optional 编译错误:参数不是可选的

It seems that I cannot pass any argument out of the Private Sub Worksheet_BeforeRightClick . 看来我无法从Private Sub Worksheet_BeforeRightClick传递任何参数。

Could you help me out somehow? 你能以某种方式帮助我吗?
The code below: 下面的代码:

Private Sub Worksheet_BeforeRightClick(ByVal Target As Range, Cancel As Boolean)
    On Error GoTo forward
    'checkinh if column A or B are non-empty (so that the code won\t work below the table:
    If Cells(Target.Row, 1).Value <> 0 Or Cells(Target.Row, 2).Value <> 0 Then
        'only column F and G, also exclude firs row (headings):
        If Target.Value = 0 And Target.Column > 5 And Target.Column < 8 And Target.Row > 1 And Target.Interior.Pattern = xlNone Then
            If Target.Column = 6 And Cells(Target.Row, 7).Value = UCase(Left(Environ("username"), 2)) Then
                r = Target.Row
                TickTock
            End If
            Cancel = True
            Target = UCase(Left(Environ("username"), 2))
            'm doesn't add a time
            If Target.Column = 7 Then
                Sheets(1).Cells(Target.Row, Target.Column - 2).Value = Format(Now - (61 / 1440), "hh:mm")
            End If
            'if there is no c then m adds a time
            If Target.Column = 6 And Cells(Target.Row, Target.Column + 1).Interior.Pattern <> xlNone Then
                Sheets(1).Cells(Target.Row, Target.Column - 1).Value = Format(Now - (61 / 1440), "hh:mm")
            End If
        End If
    End If

    Exit Sub
forward:
    Exit Sub

End Sub

Private Sub TickTock(r As Integer)
    Cells(r, 6).Interior.Color = 65535
End Sub

The TickTock Sub has no optional arguments, but in your event handler you're calling it with no argument. TickTock Sub没有可选参数,但是在事件处理程序中,您没有参数调用它。

Maybe you need to be using: 也许您需要使用:

TickTock r

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

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