【发布时间】:2019-02-09 00:18:44
【问题描述】:
如何使第 6 (F) 列和第 13 (M) 列仅在我双击时才接受输入,这意味着它不应接受任何数字、字母或符号,甚至“删除”按钮,而是双击?
以下是我整理出来的代码:
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
Checking whether target cell is in third column
Select Case Target.Column
Case 6, 13
If Not Intersect(Target, Range("F2:F13, M2:M13")) Is Nothing Then Cancel = True
'Prevent cell going into Edit Mode
Cancel = True
'Changing font type of the cell
Target.Font.Name = "Marlett"
'Checking if target cell value is blank then inserting tick
If Target = "" Then
Target = "a"
Else
MsgBox "You cannot modify the cell."
End If
End Select
End Sub
【问题讨论】:
-
我刚刚注意到您在代码中的两个位置将
Cancel设置为 true。首先在您的 IF 语句中,然后在此之后。所以你的Cancel的值总是正确的。其次,您不会使用Cancel的值来决定下一步应该采取什么行动。
标签: excel vba double-click