首页 > 解决方案 > 绘图宏输出数组

问题描述

我正在尝试使用以下代码绘制来自各种工作表的多个单元格列表的输出:

Option Explicit

Function MergeRanges(ParamArray arguments() As Variant) As Variant()
Dim cell As Range, temp() As Variant, argument As Variant
Dim iRows As Integer, i As Integer
ReDim temp(0)

For Each argument In arguments
  For Each cell In argument
    If cell <> "" Then
      temp(UBound(temp)) = cell
      ReDim Preserve temp(UBound(temp) + 1)
    End If
  Next cell
Next argument

ReDim Preserve temp(UBound(temp) - 1)
iRows = Range(Application.Caller.Address).Rows.Count
For i = UBound(temp) To iRows
  ReDim Preserve temp(UBound(temp) + 1)
  temp(UBound(temp)) = ""
Next i

MergeRanges = Application.Transpose(temp)

End Function

出于某种原因,当我尝试绘制组合来自其他工作表的单元格的数组时,图表不会在 X 轴上产生正确的值 - 它没有正确读取数组。例如,当我从下表(即上述代码的输出)绘制累积 P/L 与日期时,XY 散点图错误地绘制了日期轴:

输出值表 - 来自其他工作表的组合列表

图表在 x 轴上显示不正确的日期值

只是想知道是否有人对这里可能出现的问题有任何想法?

标签: arraysexcelvbaexcel-charts

解决方案


推荐阅读