|
- Sub getData()
- Dim rs, r%, arr, i%, x
- With ActiveSheet
- r = .Cells(.Rows.Count, 1).End(xlUp).Row
- arr = .Range("A4:B" & r)
- End With
- Set rs = CreateObject("ADODB.Recordset")
- With rs
- .CursorLocation = 3
- .Open "select * from 流水 where 日期=#" & ActiveSheet.[B1].Value & "#", _
- "provider=Microsoft.ACE.OLEDB.12.0;data source=" & ThisWorkbook.Path & "\Database1.accdb", 1, 1
- For i = 1 To UBound(arr)
- .movefirst
- .Find .fields(2).Name & "='" & arr(i, 1) & "'"
- If .EOF Then
- arr(i, 2) = ""
- Else
- arr(i, 2) = rs(3).Value
- End If
- Next
- .Close
- End With
- Set rs = Nothing
- ActiveSheet.Range("A4:B" & r) = arr
- End Sub
复制代码 |
|