打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
Excel|Excel VBA 多条件查找数据
这样应该OK了
  1. Private Sub CommandButton1_Click()
  2.     Dim Cnn, strSql$, Rst, a%
  3.     Set Cnn = CreateObject("adodb.connection")
  4.     Application.ScreenUpdating = False
  5.     Cnn.Open "provider=microsoft.jet.oledb.4.0;extended properties=excel 8.0;data source=" & ThisWorkbook.FullName
  6.     strSql = "select 姓名,班级,学号,入学年月,性别,喜好,数据1,数据2 FROM [数据表$A:H] where "
  7.     For a = 3 To 7
  8.         strSql = strSql & Cells(a, "j") & " like '%" & Cells(a, "k") & "%' and "
  9.     Next
  10.     strSql = Left(strSql, Len(strSql) - 5)
  11.     Set Rst = Cnn.Execute(strSql)
  12.     Range([h2], Cells(Rows.Count, "a").End(3)).ClearContents
  13.     [a2].CopyFromRecordset Rst
  14.     Rst.Close
  15.     Set Rst = Nothing: Set Cnn = Nothing
  16.     Application.ScreenUpdating = True
  17. End Sub
复制代码
本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
VBA进阶-在VBA中使用SQL语句生成统计报表
如何在Excel中使用SQL语言?
用ADO SQL方法将txt文本数据导入Excel | VBA实例教程
Excel 怎样指定导入数据列? - ExcelVBA程序开发 - Excel Home论...
VBA|数据库操作01:使用ADO访问数据库
我在asp中用excel 组件制作web报表,Set ExAp=Server.Create...
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服