How to read formulas of Calculated Columns in an Excel Table/ListObject without any data rows

牧云@^-^@ 提交于 2019-12-05 14:49:23

Here is a workaround that will work whether the table has rows or not.

getListColumnFormulae - Adds a row to table - Fills an 1 dimensional base 1 array with the formulas for all the ListColumns - Deletes the row - Return the array



Function getListColumnFormulae(tbl As ListObject)
    Dim Formulae
    On Error Resume Next
    With tbl.ListRows.Add
        Formulae = Application.Transpose(.Range.Formula)
        Formulae = Application.Transpose(Formulae)
        getListColumnFormulae = Formulae
        .Delete
    End With
    On Error GoTo 0
End Function

Sub FormulaeMessage()
    Dim Data
    Dim tbl As ListObject
    Set tbl = Worksheets("Sheet2").ListObjects(1)
    Data = getListColumnFormulae(tbl)

End Sub
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!