- 帖子
- 2035
- 主題
- 24
- 精華
- 0
- 積分
- 2031
- 點名
- 0
- 作業系統
- Win7
- 軟體版本
- Office2010
- 閱讀權限
- 100
- 性別
- 男
- 註冊時間
- 2012-3-22
- 最後登錄
- 2024-2-1
|
9#
發表於 2012-7-12 08:30
| 只看該作者
回復 5# GBKEE
回復 8# jovi0801
我加上了一欄 "期間" (scope) 如此可以清楚地看出它們的歸屬。
純參考,希望 GBKEE 大大莫介意。- Sub Ex() ' DatePart("WW", .Rows(xi).Cells(1)) 傳回第幾週
- Dim AR, xi As Integer, xAr As Integer, Rng As Range, scope As String
-
- With Sheets("日價格")
- AR = Application.Transpose(.Range("A1").CurrentRegion.Rows(1).Value) ' 取得欄位
- xAr = 2
- xi = 2
- ReDim Preserve AR(1 To 6, 1 To xAr) ' 新增一維空白陣列
-
- Set Rng = .Cells(xi, "A") ' 一週營業的第一天日期位置
- scope = .Cells(xi, "A")
-
- Do While .Cells(xi, "A") <> ""
- If DatePart("WW", .Cells(xi, "A")) <> DatePart("WW", .Cells(xi + 1, "A")) Then
- Set Rng = Range(Rng, .Cells(xi, "E")) ' 一週營業的第一天日期位置 到 最後第一天收盤價位置
- AR(1, xAr) = Rng.Cells(1) ' 日期 Rng.Cells(1) 日期: 週一 或 .Cells(xi, "A") 日期: 週五(最後一天)
- AR(2, xAr) = Rng.Cells(1, 2) ' 開盤價
- AR(3, xAr) = Application.Max(Rng.Columns(3)) ' 最高價
- AR(4, xAr) = Application.Min(Rng.Columns(4)) ' 最低價
- AR(5, xAr) = .Cells(xi, "E") ' 收盤價
- AR(6, xAr) = scope & "-" & .Cells(xi, "A")
-
- If .Cells(xi + 1, "A") <> "" Then
- Set Rng = .Cells(xi + 1, "A")
- xAr = xAr + 1
- scope = .Cells(xi + 1, "A")
- ReDim Preserve AR(1 To 6, 1 To xAr)
- End If
- End If
- xi = xi + 1
- Loop
- End With
-
- With Sheets("周價格")
- .UsedRange.Clear
- .[A1].Resize(xAr, 6) = Application.Transpose(AR)
- End With
- End Sub
複製代碼
日價格怎麼轉變成週價格.rar (9.85 KB)
|
|