|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
Sub sdasd()
Dim cn As Object, rs As Object, sql As String, ssCondition As String
Dim strPath As String, arr()
Set cn = CreateObject("adodb.connection")
strPath = ThisWorkbook.FullName
With cn
If Application.Version > 12 Then
.provider = "Microsoft.Ace.oledb.12.0;extended properties=excel 12.0"
.Open strPath
Else
.provider = "microsoft.jet.oledb.4.0;extended properties=excel 8.0"
.Open strPath
End If
End With
With Sheet1
For i = 1 To 7
If .Cells(3, i).Value <> "" Then
ssCondition = ssCondition & .Cells(2, i).Value & " like '%" & .Cells(3, i).Value & "%' and "
End If
Next i
If ssCondition <> "" Then
ssCondition = " where " & Left(ssCondition, Len(ssCondition) - 5)
End If
sql = "select * from [数据资料$]" & ssCondition
Set rs = cn.Execute(sql)
Debug.Print sql
.Range("a7").CurrentRegion.Offset(1).Clear
.Range("a9").CopyFromRecordset rs
For i = 1 To rs.Fields.Count
.Cells(8, i).Value = rs.Fields(i - 1).Name
Next i
End With
End Sub |
评分
-
1
查看全部评分
-
|