excel - VBA - Modification of SourceData (Dynamic Range) of existing STock OHLC Chart
问题描述
I am working on Stock OHLC Chart present in Sheets("Exhibit") and selecting Data from Sheets("75Min"). However i am succeeding to choose appropriate data range but can not add at Line Nu 15 .SetSourcedata, could you please help me to get out from this problem Code is as follows.
Sub Edit75MinChartToOHLCCandlestickChart()
Dim OHLCChart As ChartObject
Dim LastRow As Integer
Dim RngSt As Integer
Sheets("75Min").Select
Range("A1").Select
Range("A1").End(xlDown).Select
LastRow = ActiveCell.Row
RngSt = LastRow - 59
RngEnd = LastRow + 15
Set OHLCChart = ThisWorkbook.Worksheets("Exhibit").ChartObjects(1)
With OHLCChart.Chart 'Worksheets("Exhibit").ChartObjects("Chart 2").Chart
.SetSourceData ThisWorkbook.Worksheets("75Min").Range(RngSt, RngEnd)
.ChartType = xlStockOHLC
.HasTitle = True
.ChartTitle.Text = "75Min Candlestick chart"
.Axes(xlValue, xlPrimary).HasTitle = False
.Axes(xlValue, xlPrimary).AxisTitle.Characters.Text = "Price"
.PlotArea.Format.Fill.ForeColor.RGB = RGB(242, 242, 242)
.ChartArea.Format.Line.Visible = msoFalse
.Parent.Name = "OHLC Chart"
End With
End Sub
Thank You
解决方案
您可以包括这些行来调整 Y 轴刻度:
Dim Ymin As Double, Ymax As Double
Ymin = WorksheetFunction.Min(MyRng)
Ymax = WorksheetFunction.Max(MyRng)
With OHLCChart.Chart.Axes(xlValue)
.MinimumScale = Ymin
.MaximumScale = Ymax
End With
但这些可能是丑陋的轴限制。我在 Excel VBA 中编写了一个名为“Calculate Nice Axis Scales”的教程,其中包含一个算法,可以稍微向外调整最小值和最大值,以便刻度更易于阅读。
推荐阅读
- arrays - Pyspark:检查元组是否包含在元组列表中
- r - 使用 RenderPlot 在 R 中显示图形
- r - 用相同的列R替换基于另一个df的列中的一些值
- regex - 如何使用 -Filter(使用正则表达式)?
- android - Android Q foregroundServiceType 属性
- javascript - 索引表达式不是类型
- .net - .Net TimeZoneInfo.GetUtcOffset 如何工作?
- hyperledger-fabric - HyperLedger composer v0.20.8 启动业务网络时报错
- android - 是否可以在我们的应用程序活动中调用另一个应用程序?
- sql - 连接和计算来自不同表的行