|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
Sub kk()
Dim cn As Object, rs As Object, strCondition As String, sql As String
Set cn = CreateObject("Adodb.Connection")
With cn
If Val(Application.Version) < 12 Then
.provider = "Microsoft.Jet.Oledb.4.0;Extended Properties=Excel 8.0"
.Open ThisWorkbook.FullName
Else
.provider = "Microsoft.Ace.Oledb.12.0;Extended Properties=Excel 12.0"
.Open ThisWorkbook.FullName
End If
End With
With Worksheets("信息台账")
For i = 2 To 4
If .Cells(i, 2) <> "" Then
strCondition = strCondition & .Cells(i, 1).Value & " Like '%" & .Cells(i, 2).Value & "%' and "
End If
Next i
If strCondition = "" Then
sql = "select 序号,库位编号,存货名称,规格,单位 from [数据源$]"
Else
strCondition = " where " & Left(strCondition, Len(strCondition) - 5)
sql = "select 序号,库位编号,存货名称,规格,单位 from [数据源$]" & strCondition
End If
Set rs = cn.Execute(sql)
.Range("a7:e65536").Clear
.Range("a7").CopyFromRecordset rs
End With
cn.Close
Set cn = Nothing
Set rs = Nothing
End Sub
|
评分
-
2
查看全部评分
-
|