|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
Public Sub test()
Dim arr, i, j, wlmc, rng As Range, r As Range
arr = Sheet2.Range("a1").CurrentRegion.Value
Set cnn = CreateObject("adodb.connection")
Set rst = CreateObject("ADODB.RecordSet")
With cnn
.Open "Provider=Microsoft.Ace.oledb.12.0;extended properties='excel 12.0;HDR=yes';data source=" & ThisWorkbook.FullName
Sql = "select 单据日期,物料编码,物料名称 from [领料明细$] order by 物料名称,单据日期 DESC "
End With
rst.Open Sql, cnn, 1, 3
arr = Application.WorksheetFunction.Transpose(rst.getrows)
With Sheet1
Set rng = .[c3:c21]
For Each r In rng
wlmc = r
k = 0
For i = LBound(arr) To UBound(arr)
If wlmc = arr(i, 3) Then
k = k + 1
If k > 1 Then
r.Offset(0, k - 1).Value = CDate(arr(i - 1, 1)) - CDate(arr(i, 1))
End If
End If
Next
Next
End With
End Sub
|
评分
-
1
查看全部评分
-
|