如何在双击时才能使第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
当用户在工作表中键入内容时,触发的事件是Change
和SelectionChange
。 BeforeDoubleClick
仅在双击时触发,因此当然只有键入时才会运行。
执行所需操作的最简单方法是转到“审阅”选项卡>“保护表”,然后单击“允许用户编辑范围”。 VBA仅用于标记F2:13和H2:13中的复选框。