新代码供参考。。。- Sub ykcbf() '//2024.2.19
- Set Fso = CreateObject("scripting.filesystemobject")
- Set d = CreateObject("Scripting.Dictionary")
- Application.ScreenUpdating = False
- Set sh = ThisWorkbook.Sheets("2024年")
- p = ThisWorkbook.Path & ""
- On Error Resume Next
- For Each sht In Sheets
- If Val(sht.Name) Then
- If IsArray(sht.UsedRange) Then
- With sht
- r = .Cells(Rows.Count, 1).End(3).Row
- c1 = .Rows(3).Find("扫码笔数", , , , , 1).Column
- c2 = .Rows(3).Find("支付笔数", , , , , 1).Column
- c3 = .Rows(3).Find("支付金额", , , , , 1).Column
- c4 = .Rows(3).Find("库存合计", , , , , 1).Column
- arr = .[a1].Resize(r, c3)
- For i = 4 To UBound(arr)
- s = arr(i, 2) & "|" & .Name
- d(s) = Array(arr(i, c1), arr(i, c2), Val(arr(i, c3)), arr(i, c4))
- Next
- End With
- End If
- End If
- Next
- With sh
- .UsedRange.Offset(2, 1) = ""
- arr = .UsedRange
- For i = 3 To UBound(arr)
- n = 0
- For j = 2 To UBound(arr, 2) Step 32
- n = n + 1
- For x = 1 To 31
- s = arr(i, 1) & "|" & arr(2, j + x - 1)
- If d.exists(s) Then
- arr(i, j + x - 1) = d(s)(n - 1)
- End If
- Next
- Next
- Next
- .Columns(1).NumberFormatLocal = "@"
- .UsedRange = arr
- .UsedRange.EntireColumn.AutoFit
- End With
- Application.ScreenUpdating = True
- End Sub
复制代码
|