|
第一段使用有标题:- Private Sub Worksheet_Change(ByVal Target As Range)
- Dim cn As Object, Sql$, sh As Worksheet, rowend&
- Dim RST As New ADODB.Recordset
- Dim arr
- If Target.Address = [b1].Address And Not IsEmpty([b1]) Then
- Set cn = CreateObject("ADODB.Connection")
- ' cn.Open "provider=microsoft.jet.oledb.4.0;extended properties='excel 8.0;hdr=no';data source=" & ThisWorkbook.FullName
- cn.Open "provider=microsoft.jet.oledb.4.0;extended properties=excel 8.0;data source=" & ThisWorkbook.FullName
- Range("A4:L" & [a65536].End(xlUp).Row + 1).ClearContents
- For Each sh In Worksheets
- If sh.Name <> "Result" Then
- Sql = ""
- arr = sh.[a1].CurrentRegion
- For i = 1 To UBound(arr, 2)
- Sql = Sql & arr(1, i) & " like '%" & [b1].Text & "%' or "
- Next
- Sql = Left(Sql, Len(Sql) - 3)
- Sql = "select * from [" & sh.Name & "$] where " & Sql
- [a65536].End(xlUp).Offset(1, 0).CopyFromRecordset cn.Execute(Sql)
- End If
- Next
- cn.Close: Set cn = Nothing
- End If
- If Target.Address = [g1].Address And Not IsEmpty([g1]) Then
- Set RST = CreateObject("Adodb.Recordset")
- Set cn = CreateObject("ADODB.Connection")
- cn.Open "provider=microsoft.jet.oledb.4.0;extended properties='excel 8.0;hdr=no';data source=" & ThisWorkbook.FullName
- Sql = ""
- For i = 1 To [iv3].End(xlToLeft).Column
- Sql = Sql & "f" & i & " like '%" & [g1].Text & "%' or "
- Next
- Sql = Left(Sql, Len(Sql) - 3)
- rowend = [a65536].End(xlUp).Row
- Sql = "select * from [Result$a4:h" & rowend & "] where " & Sql
- RST.Open Sql, cn, adOpenStatic
- [a4].CopyFromRecordset RST
- Range("A" & 4 + RST.RecordCount & ":L" & rowend + 1).ClearContents
- cn.Close: Set cn = Nothing
- End If
- End Sub
复制代码 |
评分
-
1
查看全部评分
-
|