|
参与一下。。。
- Sub ykcbf() '//2024.9.19
- Application.ScreenUpdating = False
- Set fso = CreateObject("scripting.filesystemobject")
- Set d = CreateObject("Scripting.Dictionary")
- Set sh = ThisWorkbook.Sheets("即时库存")
- Dim tm: tm = Timer
- With sh
- c = .Cells(2, "XFD").End(1).Column
- For j = 1 To 51
- s = .Cells(2, j)
- d(s) = j
- Next
- num = Val(.[bd2].Value)
- End With
- ReDim brr(1 To 100000, 1 To 100)
- p = ThisWorkbook.Path & ""
- For Each f In fso.GetFolder(p).Files
- If LCase$(f.Name) Like "*.xls*" Then
- If InStr(f.Name, ThisWorkbook.Name) = 0 Then
- fn = fso.GetBaseName(f)
- Set Wb = Workbooks.Open(f, 0)
- With Wb.Sheets(1)
- arr = .UsedRange
- For i = 2 To UBound(arr)
- If Val(arr(i, 1)) Then
- m = m + 1
- For j = 1 To UBound(arr, 2)
- s = arr(1, j)
- If d.exists(s) Then
- brr(m, d(s)) = arr(i, j)
- End If
- Next
- End If
- brr(m, 52) = f.Name
- brr(m, 53) = .Name
- brr(m, 55) = Left(brr(m, 1), 3)
- k = CDate(brr(m, 41)) - CDate(Date)
- If brr(m, 41) = Empty Then brr(m, 54) = "正常库存"
- Select Case k
- Case Is > num
- brr(m, 54) = "正常库存"
- Case Is < 0
- brr(m, 54) = "过期库存"
- Case Else
- brr(m, 54) = "临保库存"
- End Select
- Next
- End With
- Wb.Close False
- End If
- End If
- Next f
- With sh
- .UsedRange.Offset(2).ClearContents
- .[a3].Resize(m, 55) = brr
- End With
- Set d = Nothing
- Application.ScreenUpdating = True
- MsgBox "共用时:" & Format(Timer - tm) & "秒!"
- End Sub
复制代码
|
|