简体   繁体   English

Excel剪切的VBA代码

[英]VBA code for Excel cut and paste

The user can enter data in that cell: 用户可以在该单元格中输入数据:

  1. By choosing from a predefined list of options (scrolling a drop down list) 通过从预定义的选项列表中进行选择(滚动下拉列表)

  2. By typing in directly the alphanumeric value (all numbers, all letters, or a combination of the two) 通过直接输入字母数字值(所有数字,所有字母或两者的组合)

  3. By doing copy (from other documents) and paste the identifier in that cell 通过复制(来自其他文档)并将标识符粘贴到该单元格中

I do not want to give the user the right to perform option 3? 我不想授予用户执行选项3的权利? Is there a VBA code to accomplish that? 是否有VBA代码可以实现这一目标?

Excel has always had a problem with validations. Excel一直存在验证问题。 They work fine when you need someone to choose from a list or enter specific data, but the moment a user copies data from someone else and Pastes in a Validation Cell, it ignores validations and allows it 当您需要某人从列表中选择或输入特定数据时,它们可以正常工作,但是当用户从其他人复制数据并将其粘贴到“验证单元”中时,它会忽略验证并允许它

Here is an example: 这是一个例子:

Private Sub Worksheet_Change(ByVal Target As Range)
    Application.EnableEvents = False
    If Target = Range("A1") Then
        If Not (Target >= 1 And Target <= 10) Then
            Application.Undo
            MsgBox "Please enter value between 1 to 10", vbOKOnly + vbCritical
        End If
    End If
    Application.EnableEvents = True
End Sub

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM