Excel宏VBA:如何只允许双击作为特定列的输入?

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

如何在双击时才能使第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
excel-vba double-click
1个回答
0
投票

当用户在工作表中键入内容时,触发的事件是ChangeSelectionChangeBeforeDoubleClick仅在双击时触发,因此当然只有键入时才会运行。

执行所需操作的最简单方法是转到“审阅”选项卡>“保护表”,然后单击“允许用户编辑范围”。 VBA仅用于标记F2:13和H2:13中的复选框。

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