【问题标题】:how to save a formula array in a cell to a vba variable如何将单元格中的公式数组保存到vba变量
【发布时间】:2013-07-07 18:00:00
【问题描述】:

我该怎么做:

For j = 1 To MaxCol + 1
    'Select the cell on which you want to save the formula

    Cells(7, j).Select

    my_story_tab_array(j) = ActiveCell.FormulaArray
Next

活动工作表中的某些单元格不是公式数组...有些是...

我想将它们保存到我的代码(公共/全局变量)中的数组()中,以便以后可以恢复它们...

TIA。

【问题讨论】:

  • 顺便说一句 - 我只保存工作表的第 7 行,因为每列的所有公式在整个工作表中都是相同的

标签: vba save global-variables public array-formulas


【解决方案1】:

我想这会对你有所帮助:)

    Sub editedmacro()
    Dim my_story_tab_array() As Variant 'Array where the formula will be store
    MaxCol = 2
    For j = 1 To MaxCol + 1
        ReDim my_story_tab_array(MaxCol + 1) 'set size of the array
        Cells(7, j).Select 'Select the cell on which you want to save the formula

        my_story_tab_array(j) = ActiveCell.FormulaArray 'store the current cell value into array
        MsgBox (my_story_tab_array(j))
    Next
   End Sub

问候

【讨论】:

  • 谢谢-我已经尝试过了-当您查看内存中数组的转储时-我们在工作表 Cell(7,j) 上的原始单元格中的任何数组公式正在尝试复制 - 存储为常规公式?换句话说,当我将公式复制回它的原始单元格时... { ... } 丢失了
【解决方案2】:

你正在寻找某事。像这样:

Sub example()
With ActiveWorkbook.Sheets(1).Range(Cells(7, 3), Cells(7, 4))
    .Formula = "=SUM($A$2, $A$3) * 9"
    .FormulaArray = .FormulaR1C1
End With
End Sub

问候

【讨论】:

    猜你喜欢
    • 2017-01-13
    • 2015-10-09
    • 1970-01-01
    • 1970-01-01
    • 2021-12-26
    • 1970-01-01
    • 2013-07-02
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多