Excel精英培训网

 找回密码
 注册
数据透视表40+个常用小技巧,让你一次学会!
查看: 2117|回复: 3

[已解决]请教一个事件程序的问题

[复制链接]
发表于 2015-6-13 22:50 | 显示全部楼层 |阅读模式
当工作表1中的A列不断添加数据时,工作表2和工作表3中的A列能用数据有效性下拉出表1中的数据
最佳答案
2015-6-13 23:21
  1. Private Sub Worksheet_SelectionChange(ByVal Target As Range)
  2.     Dim ar, d
  3.     Set d = CreateObject("scripting.dictionary")
  4.     With Sheets("Sheet1")
  5.         ar = .Range("A1:a" & .Cells(Rows.Count, 1).End(xlUp).Row).Value
  6.     End With
  7.     For i = 1 To UBound(ar)
  8.         d(ar(i, 1)) = ""
  9.     Next
  10.     If Target.Column = 1 Then
  11.         With Target.Validation
  12.             .Delete
  13.             .Add Type:=xlValidateList, Formula1:=Join(d.keys, ",")
  14.         End With
  15.     End If
  16. End Sub
复制代码
下拉去重的

Book1.rar

1.44 KB, 下载次数: 2

excel精英培训的微信平台,每天都会发送excel学习教程和资料。扫一扫明天就可以收到新教程
 楼主| 发表于 2015-6-13 22:50 | 显示全部楼层
回复

使用道具 举报

发表于 2015-6-13 23:11 | 显示全部楼层
'在工作表2和工作表3中选择A列单元格的事件
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Target.Column = 1 Then
    With Target.Validation
        .Delete
        .Add Type:=xlValidateList, Formula1:="=Sheet1!" & Sheet1.Range("A1").CurrentRegion.Address
    End With
End If
End Sub
回复

使用道具 举报

发表于 2015-6-13 23:21 | 显示全部楼层    本楼为最佳答案   
  1. Private Sub Worksheet_SelectionChange(ByVal Target As Range)
  2.     Dim ar, d
  3.     Set d = CreateObject("scripting.dictionary")
  4.     With Sheets("Sheet1")
  5.         ar = .Range("A1:a" & .Cells(Rows.Count, 1).End(xlUp).Row).Value
  6.     End With
  7.     For i = 1 To UBound(ar)
  8.         d(ar(i, 1)) = ""
  9.     Next
  10.     If Target.Column = 1 Then
  11.         With Target.Validation
  12.             .Delete
  13.             .Add Type:=xlValidateList, Formula1:=Join(d.keys, ",")
  14.         End With
  15.     End If
  16. End Sub
复制代码
下拉去重的
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|Archiver|Excel精英培训 ( 豫ICP备11015029号 )

GMT+8, 2024-5-14 22:52 , Processed in 0.281391 second(s), 14 queries , Gzip On, Yac On.

Powered by Discuz! X3.4

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表