|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
- Sub test()
- Dim r%, i%, c%, j%
- Dim arr, brr
- With Worksheets("sheet1")
- c = .Cells(1, .Columns.Count).End(xlToLeft).Column
- r = .UsedRange.Find(what:="*", lookat:=xlWhole, LookIn:=xlValues, searchorder:=xlByRows, searchdirection:=xlPrevious).Row
- arr = .Range("b1").Resize(r, c - 1)
- zs = Application.WeekNum(Date)
- ReDim brr(1 To 2, 1 To UBound(arr, 2))
- For j = 1 To UBound(arr, 2)
- brr(1, j) = j
- If arr(1, j) >= zs Then
- brr(2, j) = arr(1, j)
- Else
- brr(2, j) = arr(1, j) + 52
- End If
- Next
- For i = 1 To UBound(brr, 2) - 1
- p = i
- For j = i + 1 To UBound(brr, 2)
- If brr(2, p) > brr(2, j) Then
- p = j
- End If
- Next
- If p <> i Then
- For k = 1 To UBound(brr)
- temp = brr(k, i)
- brr(k, i) = brr(k, p)
- brr(k, p) = temp
- Next
- End If
- Next
- ReDim crr(1 To UBound(arr), 1 To UBound(arr, 2))
- For k = 1 To UBound(brr, 2)
- For i = 1 To UBound(arr)
- crr(i, k) = arr(i, brr(1, k))
- Next
- Next
- End With
- With Worksheets("sheet2")
- .Cells.Clear
- .Range("a1") = "Week"
- .Range("b1").Resize(UBound(crr), UBound(crr, 2)) = crr
- End With
- End Sub
复制代码 |
|