设为首页收藏本站Access中国

Office中国论坛/Access中国论坛

 找回密码
 注册

QQ登录

只需一步,快速开始

返回列表 发新帖
查看: 3135|回复: 6
打印 上一主题 下一主题

[函数/公式] 小妖同学请进!!!

[复制链接]
1#
发表于 2011-12-13 18:24:19 | 显示全部楼层
看样子,被点名的小妖同学缺席了?{:soso_e128:}。
俺用ADO随便做了一个。实际上,用内存数组会更好些,只是写起来也更加麻烦,主要因为多维数组切换成一维数组实在不方便。

  1. '注意事项:  1、在表1上需要加一行表头。
  2. '           2、需要引用ADO库(Microsoft ActiveX Data Object),可能版本号不同,但不影响使用。
  3. '           3、使用前必须确保先启用宏(Office2003 版位置:工具\宏\宏安全性;
  4. '                                   2010版本位置:文件\选项\受信任中心\受信任中心设置\宏设置)。
  5. '           4、如果修改其它内容,请修改ssql语句和其它相关内容以适。

  6. '编写: Roych
  7. '日期: 2012-12-13

  8. Sub ImpData()
  9. Dim cnn As New ADODB.Connection
  10. Dim rst As New ADODB.Recordset
  11. Dim ssql As String
  12. Sheets("表2").Range("A:B").ClearContents
  13. cnn.Open "provider=microsoft.jet.oledb.4.0;extended properties=excel 8.0;data source=" & ThisWorkbook.FullName
  14. ssql = "select * from( select 公司,产品1 from [表1$] union select 公司,产品2 from [表1$] union " _
  15.         & "select 公司,产品3 from [表1$] union select 公司,产品4 from [表1$] union " _
  16.         & "select 公司,产品5 from [表1$] union select 公司,产品6 from [表1$] union " _
  17.         & "select 公司,产品7 from [表1$] union select 公司,产品8 from [表1$] union " _
  18.         & "select 公司,产品8 from [表1$] union select 公司,产品10 from [表1$] union " _
  19.         & "select 公司,产品11 from [表1$] union select 公司,产品12 from [表1$] union " _
  20.         & "select 公司,产品13 from [表1$] union select 公司,产品14 from [表1$] union " _
  21.         & "select 公司,产品15 from [表1$] union select 公司,产品16 from [表1$] )  where isnull(产品1)=False"
  22. rst.Open ssql, cnn, adOpenKeyset, adLockOptimistic
  23. Sheets("表2").[a1].CopyFromRecordset rst
  24. rst.Close
  25. Set rst = Nothing
  26. cnn.Close
  27. Set cnn = Nothing
  28. End Sub
复制代码

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?注册

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

本版积分规则

QQ|站长邮箱|小黑屋|手机版|Office中国/Access中国 ( 粤ICP备10043721号-1 )  

GMT+8, 2024-5-16 07:46 , Processed in 0.102914 second(s), 24 queries .

Powered by Discuz! X3.3

© 2001-2017 Comsenz Inc.

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