【问题标题】:Excel Macro VBA: How to allow ONLY double click as input on a specific column?Excel Macro VBA:如何只允许双击作为特定列的输入?
【发布时间】: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


【解决方案1】:

当用户在 Worksheet 中键入内容时,触发的事件是 ChangeSelectionChangeBeforeDoubleClick 只在他们双击时触发,所以如果他们只输入当然不会运行。

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

【讨论】:

    猜你喜欢
    • 2019-02-09
    • 2017-08-13
    • 1970-01-01
    • 2022-01-20
    • 1970-01-01
    • 2017-08-11
    • 2018-08-05
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多