【问题标题】:trouble plotting graph using userfom time interval data使用 userfom 时间间隔数据绘制图表时遇到问题
【发布时间】:2021-02-19 01:43:58
【问题描述】:

我在 .HasTitle = True 处遇到错误 438。 chtChart 小节有问题,因为我将 .charttype 放在第三行,Excel 总是提示我有 438 错误 编辑代码:

    Dim chtChart As ChartObject
    Dim maxscale As Long, LastRowOfA As Long
    Dim xAxes As Axis, yAxes As Axis
    Set chtChart = ActiveSheet.ChartObjects(1)
    maxscale = ActiveSheet.Cells(LastRowOfA, 1)
    LastRowOfA = ActiveSheet.Cells(Rows.Count, 1).End(xlUp).Row


    With chtChart
        .HasTitle = True
        .ChartTitle.Text = "X VS Y"
        .ChartType = xlXYScatterLinesNoMarkers
        .SeriesCollection.NewSeries
        With .SeriesCollection(1)
            .XValues = ActiveSheet.Range("A2:A" & LastRowOfA)
            .Values = ActiveSheet.Range(Range("B2:B" & LastRowOfB))
        End With
        
        Set xAxes = .Axes(xlCategory, xlPrimary)
            With xAxes
                .HasTitle = True                               
                .AxisTitle.Text = "Category (X) Axis"             
                .MinimumScale = 0                              
                .MaximumScale = maxscale                       
                .MajorUnit = tbData
            End With
        
        Set yAxes = .Axes(xlValue, xlPrimary)
            With yAxes                                          
                .HasTitle = True
                .AxisTitle.Text = "Category (Y) Axis"
                .MinimumScaleIsAuto = True                      
                .MaximumScaleIsAuto = True                      
            End With
    End With

【问题讨论】:

  • 您尚未将chtChart 设置为图表对象...ColumnARngData 上的单元格格式是什么?
  • 我该怎么做?是否设置了 chtChart = ActiveSheet.ChartObjects?格式一般
  • 图表已经存在了吗?我看不到你的床单...
  • 图表不存在。

标签: excel vba


【解决方案1】:

如果只有一个图表对象,请执行以下操作。

Set chtChart = ActiveSheet.ChartObjects(1)
with chtChart.Chart
.....

【讨论】:

  • 代码可以工作,但为什么在 .MinimumScale 上它不存在?我收到了一个调用错误 438
  • @Chewjunnie,参考This
  • @Chewjunnie,首先,您需要设置 .ChartType。您只能在散点图中指定 x 轴的刻度。而且你还必须设置轴。
  • 我做了,但我仍然遇到错误 438。为什么会这样?
  • @Chewjunnie,而不是 With chtChartWith chtChart.chart。图表对象不是图表。
猜你喜欢
  • 1970-01-01
  • 2013-09-06
  • 2020-09-12
  • 1970-01-01
  • 2021-08-15
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-04-09
相关资源
最近更新 更多