- 帖子
- 2035
- 主題
- 24
- 精華
- 0
- 積分
- 2031
- 點名
- 0
- 作業系統
- Win7
- 軟體版本
- Office2010
- 閱讀權限
- 100
- 性別
- 男
- 註冊時間
- 2012-3-22
- 最後登錄
- 2024-2-1
|
5#
發表於 2012-4-15 19:05
| 只看該作者
回復 4# GBKEE
謝謝您的費心幫忙,我只異動了處理 ActiveChart.SetSourceData 的內容修正 (之前輸入最多三項的限制,可能是我當時有打錯字,
以致誤以為不行),修正內容如下:
mainPowerForce 模組修正內容: .SetSourceData Source:=Range("統計圖表!$B$1:統計圖表!$B$" & totalRows & ", 統計圖表!$F$1:統計圖表!$F$" & totalRows & ", 統計圖表!$I$1:統計圖表!$J$"
& totalRows & ", 統計圖表!$V$1:統計圖表!$V$" & totalRows) ' 圖示會分別顯示出 成交價、主力界入、散戶方向、以及成交量。
setRowColumn 模組修正內容: ActiveChart.SetSourceData Source:=Range("統計圖表!$B$1:統計圖表!$B$" & totalRows & ", 統計圖表!$F$1:統計圖表!$F$" & totalRows & ",
統計圖表!$I$1:統計圖表!$J$" & totalRows & ", 統計圖表!$V$1:統計圖表!$V$" & totalRows) ' 圖示會分別顯示出 成交價、主力界入、散戶方向、以及成交量。
圖表還真難搞呢! 幸慶終於順利解決了,作業上因為要將目前已匯入實際資料的資料列數紀錄,並同步修正結果卻惹出了一堆問題 (400, 1004, Automation 等等),命都差點丟了!
我將程式代碼附上,以幫助有此需求的同好找到好工作、或好事業。
再次向您說聲感謝您!- Sub DrawAll()
- Call drawStatistics
- Call drawOmegaCharts
- End Sub
- Sub drawStatistics()
- drawCharts ("統計圖表")
- End Sub
- Sub drawOmegaCharts()
- drawCharts ("Omega")
- End Sub
- Sub removeCharts(st As String)
- Dim oShape As Shape
- Dim str As String
-
- str = ActiveSheet.Name
- Sheets(st).Select
-
- For Each oShape In ActiveSheet.Shapes
- If oShape.Type = 3 Then
- oShape.Delete
- End If
- Next
-
- Sheets(str).Select
- End Sub
- Sub drawCharts(sta As String)
- Dim str As String
-
- str = ActiveSheet.Name
- Sheets(sta).Select
- Call removeCharts(sta)
- Selection.Borders(xlDiagonalDown).LineStyle = xlNone
- Selection.Borders(xlDiagonalUp).LineStyle = xlNone
- Selection.Borders(xlEdgeLeft).LineStyle = xlNone
-
- With Selection.Borders(xlEdgeTop)
- .LineStyle = xlContinuous
- .ColorIndex = 0
- .TintAndShade = 0
- .Weight = xlThin
- End With
-
- Selection.Borders(xlEdgeBottom).LineStyle = xlNone
-
- With Selection.Borders(xlEdgeRight)
- .LineStyle = xlContinuous
- .ColorIndex = 0
- .TintAndShade = 0
- .Weight = xlThin
- End With
-
- Call mainPowerForce(sta)
-
- Cells(1, 1).Select
- Sheets(str).Select
- End Sub
- Sub mainPowerForce(sDraw As String)
- Dim totalRows As Single
- Dim counter, xRow, yCol, cHeight, cWidth, inLeft, inTop, inWidth As Integer
- Dim text As String
- Dim chartname As String
- ' Dim rXY As Range
- totalRows = Sheets("統計圖表").Range("B" & Rows.Count).End(xlUp).Row ' 傳回 B 欄所使用儲存格之最後一格之列號
- Sheets(sDraw).Select
- Cells(1, 1).Value = totalRows
-
-
- ActiveSheet.Shapes.AddChart.Select
-
- With ActiveChart
- .ChartType = xlLine ' 折線圖
-
- ' 圖示會分別顯示出 資料錄匯入之時間、成交價、主力界入、散戶方向、以及成交量。
- ' Set rXY = Union(Range("統計圖表!$B$1:統計圖表!$B$" & totalRows), Range("統計圖表!$F$1:統計圖表!$F$" & totalRows), Range("統計圖表!$I$1:統計圖表!$I$" & totalRows), Range("統計圖表!$J$1:統計圖表!$J$" & totalRows), Range("統計圖表!$V$1:統計圖表!$V$" & totalRows))
- ' .SetSourceData Source:=rXY
- .SetSourceData Source:=Range("統計圖表!$B$1:統計圖表!$B$" & totalRows & ", 統計圖表!$F$1:統計圖表!$F$" & totalRows & _
- ", 統計圖表!$I$1:統計圖表!$J$" & totalRows & ", 統計圖表!$V$1:統計圖表!$V$" & totalRows) ' 圖示會分別顯示出 成交價、主力界入、散戶方向、以及成交量。
-
- ' .SeriesCollection.Add Source:=Range("統計圖表!$V$2:統計圖表!$V$" & totalRows)
- ' .SeriesCollection(4).Name = "=統計圖表!$S$1"
-
- .SeriesCollection(1).AxisGroup = 2
- .SeriesCollection(2).ChartType = xlLine ' 折線圖
-
- .SeriesCollection(4).ChartType = xlColumnClustered ' 堆疊直條圖
-
-
- .Axes(xlCategory).CategoryType = xlCategoryScale
- .Axes(xlCategory).TickLabels.NumberFormatLocal = "hh:mm"
- .Axes(xlCategory).MajorTickMark = xlNone
- .Axes(xlCategory).TickLabelPosition = xlLow
-
- .Axes(xlValue, xlSecondary).TickLabels.NumberFormatLocal = "0_ " ' 代表物件的格式代碼。
- .Axes(xlValue).TickLabels.NumberFormatLocal = "0_ " ' 代表物件的格式代碼。
- End With
- With ActiveChart.SeriesCollection(1).Format.Line ' 成交價
- .Visible = msoTrue
- .ForeColor.RGB = RGB(255, 0, 0) ' 成交價指數顯示之顏色 --- 紅色
- .Transparency = 0
- End With
- With ActiveChart.SeriesCollection(2).Format.Line ' 主力界入
- .Visible = msoTrue
- .ForeColor.RGB = RGB(32, 178, 170) ' 主力界入指數顯示之顏色 --- 海洋綠色
- .Transparency = 0
- End With
- With ActiveChart.SeriesCollection(3).Format.Line ' 散戶方向
- .Visible = msoTrue
- .ForeColor.RGB = RGB(65, 105, 225) ' 散戶方向指數顯示之顏色 --- 天藍色
- .Transparency = 0
- End With
-
- With ActiveChart.SeriesCollection(4).Format.Line ' 成交量
- .Visible = msoTrue
- .ForeColor.RGB = RGB(147, 112, 219) ' 成交量指數顯示之顏色 --- 紫色
- .Transparency = 0
- End With
- xRow = 2
- yCol = 1
-
- cHeight = 488
- cWidth = 450
- inLeft = 30
- inTop = 30
- inWidth = 378
- text = "主力、散戶、與成交價、量"
- chartname = Trim(Replace(ActiveChart.Name, ActiveSheet.Name, ""))
- ActiveChart.ChartArea.Height = cHeight ' 將原本設定之高度調至適度位置
- ActiveChart.ChartArea.Width = cWidth
-
- ActiveSheet.Shapes(chartname).Left = Cells(xRow, yCol).Left ' 設定此圖表實際擺放的 X、Y 座標位置。
- ActiveSheet.Shapes(chartname).Top = Cells(xRow, yCol).Top
-
- With ActiveChart.PlotArea ' 實際繪圖區塊的範圍設定
- .InsideLeft = inLeft
- .InsideTop = inTop
- .InsideWidth = inWidth
- End With
-
- ActiveChart.SetElement (msoElementChartTitleCenteredOverlay)
- ActiveChart.ChartTitle.text = text
- ActiveChart.ChartTitle.Format.TextFrame2.TextRange.Font.Size = 16
-
- ActiveChart.Legend.Position = xlCorner ' 將圖表圖示從圖表最下方調整到圖表之右上角位置
- ' Set rXY = Nothing
- End Sub
- Sub resetRC()
- Call setRowColumn("統計圖表")
- Call setRowColumn("Omega")
- End Sub
- Sub setRowColumn(sDraw As String)
- Dim oShape As Shape
- Dim xRow, yCol, cHeight, cWidth, inLeft, inTop, inWidth As Integer
- Dim totalRows As Single
- Dim chartname As String
-
- totalRows = Sheets("統計圖表").Range("B" & Rows.Count).End(xlUp).Row ' 傳回 B 欄所使用儲存格之最後一格之列號
- Sheets(sDraw).Select
-
-
- For Each oShape In ActiveSheet.Shapes
- If oShape.Type = 3 Then
- ActiveSheet.ChartObjects(oShape.Name).Activate ' 滑鼠點在 "圖表 #" 上 (例如:主力界入)。
-
- ' 圖示會分別顯示出 資料錄匯入之時間、成交價、主力界入、散戶方向、以及 成交量。
- ' Set rXY = Union(Range("統計圖表!$B$1:統計圖表!$B$" & totalRows), Range("統計圖表!$F$1:統計圖表!$F$" & totalRows), Range("統計圖表!$I$1:統計圖表!$I$" & totalRows), Range("統計圖表!$J$1:統計圖表!$J$" & totalRows), Range("統計圖表!$V$1:統計圖表!$V$" & totalRows))
- ' ActiveChart.SetSourceData Source:=rXY
- ActiveChart.SetSourceData Source:=Range("統計圖表!$B$1:統計圖表!$B$" & totalRows & ", 統計圖表!$F$1:統計圖表!$F$" & totalRows & _
- ", 統計圖表!$I$1:統計圖表!$J$" & totalRows & ", 統計圖表!$V$1:統計圖表!$V$" & totalRows) ' 圖示會分別顯示出 成交價、主力界入、散戶方向、以及成交量。
-
- ActiveChart.SeriesCollection(4).ChartType = xlColumnClustered ' 堆疊直條圖
-
- xRow = 2
- yCol = 1
-
- cHeight = 488
- cWidth = 450
- inLeft = 30
- inTop = 30
- inWidth = 378
-
- chartname = Trim(Replace(ActiveChart.Name, ActiveSheet.Name, ""))
- ActiveChart.ChartArea.Height = cHeight ' 將原本設定之高度調至適度位置
- ActiveChart.ChartArea.Width = cWidth
-
- ActiveSheet.Shapes(chartname).Left = Cells(xRow, yCol).Left ' 設定此圖表實際擺放的 X、Y 座標位置。
- ActiveSheet.Shapes(chartname).Top = Cells(xRow, yCol).Top
-
- With ActiveChart.PlotArea ' 實際繪圖區塊的範圍設定
- .InsideLeft = inLeft
- .InsideTop = inTop
- .InsideWidth = inWidth
- End With
- End If
- Next
- ' Set rXY = Nothing
- End Sub
複製代碼
主力、散戶與價量.rar (166.05 KB)
|
|