简体   繁体   中英

VBA FormulaArray pulling data from one table to another

I have two tables. Table1 is on another sheet, where I'm trying to pull the data, Table2 is on the Header sheet, where I'm putting the data. It's an array formula, where the data will be placed over multiple cells. This seems to be where I'm getting stuck. I can't seem to get it to paste, giving me a "1004 error" (if not using databodyrange) and "method or data member not found" (if using ListColumn).

Value Bought Tracker is on the Header page FinalTableSource[Buy Value] is on the second page

Here it is now with some updated code, but I'm still getting a 1004 error.

Public Sub MakeFinalTable_Click()
'Resize Table

Dim ws As Worksheet, lo As ListObject

Set ws = Sheets("Header")
Set lo = ws.ListObjects("FinalTable")

lo.ListColumns("Value Bought Tracker").DataBodyRange.FormulaArray = "=IFERROR(INDEX(FinalTableSource[Buy Value],SMALL(IF(FinalTableSource[Buy Value]<>"",ROW(FinalTableSource[Buy Value])-ROW(INDEX(FinalTableSource[Buy Value],1,1))+1),ROWS(AA$4:AA4))),"""")"

End Sub

Thank you for any help!

Dim ws As Worksheet, lo as ListObject

Set ws = Sheets("Header")
Set lo = ws.ListObjects(1)

lo.ListColumns("Value Bought Tracker").DataBodyRange.FormulaArray = "=IFERROR(INDEX(FinalTableSource[Buy Value],SMALL(IF(FinalTableSource[Buy Value]<>"",ROW(FinalTableSource[Buy Value])-ROW(INDEX(FinalTableSource[Buy Value],1,1))+1),ROWS(AA$4:AA4))),"")"

Edit: break your lines down so there's only one thing going on in each line; then you can more-easily see where the problem is -

Public Sub MakeFinalTable_Click()

    Dim ws As Worksheet, lo As ListObject, lc As ListColumn, rng As Range

    Set ws = Sheets("Header")
    Set lo = ws.ListObjects("FinalTable")
    Set lc = lo.ListColumns("Value Bought Tracker")
    Set rng = lc.DataBodyRange

    rng.FormulaArray = "=IFERROR(INDEX(FinalTableSource[Buy Value]," & _
                       "SMALL(IF(FinalTableSource[Buy Value]<>""""," & _
                       "ROW(FinalTableSource[Buy Value])-" & _
                       "ROW(INDEX(FinalTableSource[Buy Value],1,1))+1),ROWS(AA$4:AA4))),"""")"

End Sub

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM