|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
- Sub test0()
- Dim Conn As Object, SQL As String, strConn As String, s As String
- Dim ar, i As Long, j As Long, p As Long, y As Long
- Set Conn = CreateObject("ADODB.Connection")
- If Application.Version < 12 Then
- strConn = "Provider=Microsoft.Jet.OLEDB.4.0;Extended Properties='Excel 8.0;HDR=NO';Data Source="
- Else
- strConn = "Provider=Microsoft.ACE.OLEDB.12.0;Extended Properties='Excel 12.0;HDR=NO';Data Source="
- End If
- Conn.Open strConn & ThisWorkbook.Path & "\出入库台账.xlsx"
-
- For i = 2 To Worksheets.Count
- p = 5
- With Worksheets(i)
- SQL = "SELECT F1,F2 FROM [" & Split(.Range("A2"), ":")(1) & "$D5:F] WHERE F3='" & Split(.Range("F2"), ":")(1) & "'"
- ar = Conn.Execute(SQL).GetRows
- If IsArray(ar) Then
- For j = LBound(ar, 2) To UBound(ar, 2)
- For y = p To .Cells(Rows.Count, "D").End(xlUp).Row
- If ar(0, j) <= .Cells(y, "D").Value Then
- .Cells(y, "B") = ar(0, j)
- .Cells(y, "C") = ar(1, j)
- p = y + 1
- Exit For
- End If
- Next
- Next
- End If
- End With
- Next
-
- Conn.Close
- Set Conn = Nothing
- End Sub
复制代码 |
评分
-
1
查看全部评分
-
|