|
Sub TEST2() '取每周最后一天
Dim strFileName$, strPath$, wkb As Workbook
Dim arr, i&, vKey, dic As Object, t#
Application.ScreenUpdating = False
Set dic = CreateObject("Scripting.Dictionary")
t = Timer
strPath = ThisWorkbook.Path & "\"
strFileName = Dir(strPath & "*.xls*")
Do Until strFileName = ""
If strFileName <> ThisWorkbook.Name Then
Set wkb = Workbooks.Open(strPath & strFileName)
dic.RemoveAll
With wkb.Sheets(1)
arr = .[A1].CurrentRegion
For i = 2 To UBound(arr)
vKey = strWeekday(CStr(arr(i, 1)))
If Not dic.Exists(vKey) Then
dic(vKey) = Array(arr(i, 1), arr(i, 2))
Else
If Val(Mid(arr(i, 1), 7, 2)) > Val(Mid(dic(vKey)(0), 7, 2)) Then
dic(vKey) = Array(arr(i, 1), arr(i, 2))
End If
End If
Next i
.[A1].CurrentRegion.Offset(1).Clear
.[A2].Resize(dic.Count, 2) = Application.Rept(dic.Items, 1)
End With
wkb.Close True
End If
strFileName = Dir
Loop
Set wkb = Nothing
Application.ScreenUpdating = True
MsgBox "执行完毕!_用时: " & Format(Timer - t, "0.00") & " 秒", 64
End Sub
Function strWeekday$(strTxt$)
Dim str1&
str1 = CDate(Format(strTxt, "0000-00-00"))
strWeekday = Mid(strTxt, 1, 4) & "-" & WorksheetFunction.WeekNum(str1, 11)
End Function
|
评分
-
1
查看全部评分
-
|