0

我有一个动态散点图,它随着滑块按钮的变化而变化。为了做到这一点,我使用两个具有偏移功能的命名范围,当我移动滑块按钮增加或减少 X 和 Y 范围结束值时,这些命名范围会有所不同。当我复制这张纸时,问题就出现了。新工作表中的图表将没有序列公式中的命名范围,而是采用在第一个工作表中计算的范围,如下所示:

在第一张纸上我有这个:

=Serie('old_sheet'!$AD$3;'old_sheet'!DEF_RANGE;'old_sheet'!STRESS_RANGE;1)

但是当我复制时,新工作表中的图表将变为:

=Serie('new_sheet'!$AD$3;'new_sheet'!$G$19:$G$578;'new_sheet'!$F$19:$F$578;1)

所以我需要手动将公式更改为:

=Serie('new_sheet'!$AD$3;'new_sheet'!DEF_RANGE;'new_sheet'!STRESS_RANGE;1)

我问是否有人可以帮助我实现一个简单的按钮,将系列公式更改为我想要的。

我试图记录我为更改公式所做的步骤的宏......但它并不总是有效。

有点卡在这里......我会很感激任何帮助!

问候

4

3 回答 3

0

The following procedure is a bit of a pain, but it preserves the fragile worksheet-scoped names.

  1. Save the workbook with the worksheet and chart.
  2. Move (don't copy) the sheet with the chart to a new workbook.
  3. Close the first workbook without saving, so upon reopening it will still have the worksheet and chart in it.
  4. Save and close the new workbook with the moved worksheet and chart (e.g. TempChart.xlsx). This workbook can now serve as a template if used as in step 6 below.
  5. Reopen the original workbook.
  6. Reopen the new workbook. Move (don't copy) the worksheet and chart from the new workbook to the original workbook.

Whenever you need another copy of this worksheet and chart, reopen the new workbook as in step 6 and move the sheet into the desired existing workbook.

于 2014-03-18T13:54:09.137 回答
0

我对我拥有的一个大程序提出了一个小变化,它假设复制的工作表上有一个图表,该图表中有一个绘制的系列。

Sub FixSeriesRangeRefs()
  Const sXVALNAME As String = "DEF_RANGE"
  Const sYVALNAME As String = "STRESS_RANGE"

  Dim sFormula As String
  Dim vFormula As Variant
  Dim sXVals As String
  Dim sYVals As String

  With ActiveSheet.ChartObjects(1).Chart.SeriesCollection(1)
    sFormula = .Formula
    vFormula = Split(sFormula, ",")

    sXVals = vFormula(LBound(vFormula) + 1)
    sXVals = Left$(sXVals, InStr(sXVals, "!")) & sXVALNAME
    vFormula(LBound(vFormula) + 1) = sXVals

    sYVals = vFormula(LBound(vFormula) + 2)
    sYVals = Left$(sYVals, InStr(sYVals, "!")) & sYVALNAME
    vFormula(LBound(vFormula) + 2) = sYVals

    sFormula = Join(vFormula, ",")
    .Formula = sFormula
  End With
End Sub
于 2015-03-23T20:39:14.593 回答
0

我自己想通了......这是我使用的代码:

Private Sub CommandButton1_Click()


    sheet_name = ActiveSheet.Name
    MsgBox ("some message")
    ActiveSheet.ChartObjects("Graph_1").Activate
    ActiveChart.SeriesCollection(1).Select
    ActiveSheet.ChartObjects("Graph_1").Chart.SeriesCollection(1).Values = " '" & sheet_name      & "'!stress_range"
    ActiveSheet.ChartObjects("Graph_1").Chart.SeriesCollection(1).XValues = " '" & sheet_name & "'!def_range"


End Sub

希望这对和我有同样问题的人有用。

谢谢

于 2014-02-18T09:33:43.577 回答