提示:其它语言是由 Google 机器翻译的。 你可以访问 English 版本。
登录
x
or
x
x
马上登记
x

or

如何防止在Excel中使用下拉列表复制和粘贴单元格?

对于具有数据验证下拉列表的单元格,从另一个单元格复制内容并粘贴到该单元格时,下拉列表将消失并替换为新的粘贴内容。 在某些情况下,您想要防止通过下拉列表复制并粘贴其他内容到单元格上,您将如何处理它? 在这篇文章中,你会得到一个处理这个问题的VBA方法。

防止在Excel中使用下拉列表复制和粘贴单元格


快速防止Excel中列中的重复条目

您订购的 Kutools for Excel's 防止重复的项目 实用程序,您可以轻松防止Excel中列中的重复条目。

Office选项卡在Office中启用选项卡式编辑和浏览,使您的工作更轻松......
Kutools for Excel - 最佳办公生产力工具将解决您的大部分Excel问题
  • 重用任何东西: 将最常用或最复杂的公式,图表和其他任何内容添加到您的收藏夹中,并在将来快速重复使用它们。
  • 超过20文本功能: 从文本字符串中提取数字; 提取或删除部分文本; 将数字和货币转换为英语单词...
  • 合并工具:多个工作簿和表格合二为一; 合并多个单元格/行/列而不丢失数据; 合并重复行和总和...
  • 拆分工具:根据价值将数据拆分为多个表格; 一个工作簿到多个Excel,PDF或CSV文件; 一列到多列......
  • 粘贴跳过 隐藏/过滤行; 数和总和 按背景颜色; 创建邮件列表和 通过Cell的价值发送电子邮件...
  • 超级过滤器: 创建高级过滤方案并应用于任何工作表; 排序 按周,日,频率等; 筛选 通过大胆,公式,评论......
  • 超过300强大的功能; 适用于Office 2007-2019和365; 支持所有语言; 在公司轻松部署; 全功能60天免费试用。

箭头蓝色右泡 防止在Excel中使用下拉列表复制和粘贴单元格


1。 使用要防止复制和粘贴的下拉列表单元格打开工作表。

2。 按 其他 + F11 键同时打开 Microsoft Visual Basic应用程序 窗口。

3。 在里面 Microsoft Visual Basic应用程序 窗口中,双击左窗格中的当前工作表名称,然后将下面的VBA代码复制并粘贴到代码编辑器中。 看截图:

VBA代码:防止使用下拉列表复制和粘贴单元格

Private Sub Worksheet_Change(ByVal Target As Range)
	Dim xValue As String
	Dim xCheck1 As String
	Dim xCheck2 As String
	If Target.Count > 1 Then
		Exit Sub
		End If
		Application.EnableEvents = False
		xValue                   = Target.Value
		On Error Resume Next
		xCheck1                  = Target.Validation.InCellDropdown
		On Error GoTo 0
		Application.Undo
		On Error Resume Next
		xCheck2 = Target.Validation.InCellDropdown
		On Error GoTo 0
		If xCheck1 = xCheck2 Then
			Target = xValue
		Else
			MsgBox "No pasting allowed!"
		End If
		Application.EnableEvents = True
	End Sub

4。 按 其他 + Q 键退出 Microsoft Visual Basic应用程序 窗口。

5。 将内容粘贴到带有下拉列表的单元格时,会弹出一个对话框提醒您粘贴不被允许。 看截图:

注意:这个VBA只适用于单细胞粘贴。 如果你复制并粘贴多个单元格,它将不起作用。


箭头蓝色右泡相关文章:


Kutools for Excel - 最佳办公生产力工具提高80%的生产力

  • 重用: 快速插入 复杂的公式,图表 以及你以前用过的任何东西; 加密单元格 密码; 创建邮件列表 并发送电子邮件...
  • 超级方程式酒吧 (轻松编辑多行文字和公式); 阅读布局 (轻松读取和编辑大量单元格); 粘贴到过滤范围...
  • 合并单元格/行/列 不丢失数据; 分裂细胞含量; 组合重复的行/列...防止重复的细胞; 比较范围...
  • 选择复制或唯一 行; 选择空行 (所有细胞都是空的); 超级查找和模糊查找 在许多工作簿中; 随机选择......
  • 精确复制 多个单元格而不更改公式参考; 自动创建参考 多张表; 插入项目符号,复选框等等......
  • 提取文本,添加文本,按位置删除, 删除空间; 创建和打印分页小计; 在单元格内容和注释之间转换...
  • 超级过滤器 (将过滤方案保存并应用到其他工作表); 高级排序 按月/周/日,频率等; 特殊过滤器 用粗体,斜体......
  • 结合工作簿和工作表; 根据键列合并表; 将数据拆分为多个表格; 批量转换xls,xlsx和PDF...
  • 超过300强大的功能。 支持Office / Excel 2007-2019和365。 支持所有语言。 在您的企业或组织中轻松部署。 全功能60天免费试用。
kte tab 201905

Office选项卡为Office提供选项卡式界面,使您的工作更轻松

  • 在Word,Excel,PowerPoint中启用选项卡式编辑和阅读,Publisher,Access,Visio和Project。
  • 在同一窗口的新选项卡中打开并创建多个文档,而不是在新窗口中。
  • 通过50%提高您的工作效率,每天为您减少数百次鼠标点击!
官方底部
Say something here...
symbols left.
You are guest ( Sign Up? )
or post as a guest, but your post won't be published automatically.
Loading comment... The comment will be refreshed after 00:00.
  • To post as a guest, your comment is unpublished.
    Eva · 1 years ago
    I works BUT after you put the code you cannot UNDO anything. Not a single step back is allowed.
  • To post as a guest, your comment is unpublished.
    Dilip · 2 years ago
    No, I did not figure it out. I didn't try to resolve after a while.
  • To post as a guest, your comment is unpublished.
    arvind raj · 2 years ago
    did you manage to resolve the issue of copying and pasting into multiple cells? Thanks in advance!
  • To post as a guest, your comment is unpublished.
    Amit Jain · 2 years ago
    Hi Dilip,

    are you able to fix the issue of allowing data using paste values
  • To post as a guest, your comment is unpublished.
    Amit Jain · 2 years ago
    Hi Dilip,

    are you able to fix the issue of allowing data using paste values..i am also facing the same issue..help me on this please
  • To post as a guest, your comment is unpublished.
    jepson · 3 years ago
    Thank you very much !! works fine for me !!!
    copying into a single cell is restricted.
    but if i copy a list of cells and paste.., the paste is accepted. let me see if i can tune this up ..thanks anyways
    • To post as a guest, your comment is unpublished.
      G · 3 years ago
      Jepson, did you manage to resolve the issue of copying and pasting into multiple cells? Thanks in advance!
  • To post as a guest, your comment is unpublished.
    Abhijeet · 3 years ago
    Private Sub Worksheet_Change(ByVal Target As Range)
    Dim xValue As String
    Dim xCheck1 As String
    Dim xCheck2 As String
    If Target.Count > 1 Then
    Exit Sub
    End If
    Application.EnableEvents = False
    xValue = Target.Value
    On Error Resume Next
    xCheck1 = Target.Validation.InCellDropdown
    On Error GoTo 0
    Application.Undo
    On Error Resume Next
    xCheck2 = Target.Validation.InCellDropdown
    On Error GoTo 0
    If xCheck1 = xCheck2 Then
    Target = xValue
    Else
    MsgBox "No pasting allowed!"
    End If
    Application.EnableEvents = True
    End Sub
    This Macro not work when copy from different workbook or worksheet then so please tell me how to avoid these things also
  • To post as a guest, your comment is unpublished.
    chandan · 3 years ago
    Hi,

    above mention vba code is not run.kindly resolve.
  • To post as a guest, your comment is unpublished.
    Jai · 3 years ago
    Hi,

    While I running this macro I got this debug error "Application.Undo". Pls resolve this ASAP
  • To post as a guest, your comment is unpublished.
    Dilip · 4 years ago
    This works but when I paste value this is allowing data which is not from the drop down list. Any way to restrict any value which is not from the list.
    • To post as a guest, your comment is unpublished.
      Rao · 2 years ago
      Hi Dilip,

      Did you able to resolve the issue, i too having similar issue. I have to allow copy,paste only for drop down values in the data validation cell other i have to restrict. Can you share your solution.

      Thanks
      Rao