|
- Sub test()
- Dim dt1 As Date, dt2 As Date
- Dim i%, j%, k%, l As Byte
- Dim result(1 To 1000, 1 To 3)
- result(1, 1) = "季度"
- result(1, 2) = "价格"
- result(1, 3) = "实际日期"
- k = 1
- For i = 1991 To 2013
- For j = 3 To 12 Step 3
- dt1 = DateAdd("m", 1, DateValue(i & "-" & j & "-" & 1)) - 1
- dt2 = dt1
- l = Weekday(dt1, vbMonday)
- If l > 5 Then
- dt1 = dt1 - l + 5
- End If
- Do
- Set rg = Columns(1).Find(what:=dt1, lookat:=xlWhole)
- If rg Is Nothing Then
- dt1 = dt1 - 1
- End If
- Loop While rg Is Nothing And Month(dt1) = Month(dt2)
- If Not rg Is Nothing Then
- k = k + 1
- result(k, 1) = dt2
- result(k, 2) = rg.Offset(, 1).Value
- result(k, 3) = dt1
- End If
- Next
- Next
- Range("c1:e" & Cells(Rows.Count, "c").End(xlUp).Row).ClearContents
- Range("c1").Resize(k, UBound(result, 2)).Value = result
- MsgBox "ok"
- End Sub
复制代码 |
|