Sub yy()
Dim b(12) As Byte, c As Range
For Each c In Range([b2], [b2].End(4))
b(Month(c)) = b(Month(c)) + 1
c(1, 0).Value = Format(Month(c), "00") & "-" & Format(b(Month(c)), "000")
Next
End Sub作者: man65boy 時間: 2012-5-6 15:05
Option Explicit
Sub TEST()
Dim Brr, Y, i&, j%, T$, xR As Range, Sh
Set Y = CreateObject("Scripting.Dictionary")
Sh = Array(, Sheets("sheet2"), Sheets("sheet1"))
For j = 1 To 2
Set xR = Range(Sh(j).[A1], Sh(j).Cells(Rows.Count, "F").End(3))
Brr = xR
For i = 2 To UBound(Brr)
T = Format(Brr(i, 2), "YYYY-MM-")
Y(T) = Y(T) + 1
Brr(i, 1) = T & Format(Y(T), "000")
Next
If j = 2 Then
Intersect(xR.Offset(1, 0), [A:A]).ClearContents
xR = Brr
End If
Next
Set Y = Nothing: Set xR = Nothing: Set Sh = Nothing: Erase Brr
End Sub