下面的代码位于其中一个工作表中 - 我的意思是它不在模块中,而是在Sheet1
中是“Microsoft Excel对象”。
我一直收到以下错误:
编译错误:参数不是可选的
似乎我无法通过Private Sub Worksheet_BeforeRightClick
传递任何争论。
你能以某种方式帮助我吗? 以下代码:
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
答案 0 :(得分:1)
TickTock
Sub没有可选参数,但在你的事件处理程序中,你没有参数调用它。
也许您需要使用:
TickTock r