Search code examples
excelexcel-2013

Change table row size to another table row size


I have a table1 in one sheet that is feeded through a SQL Command, i have another table2 in another sheet that makes references to table1. I need table2 to resize the number of rows according to table1, how can i do that (Hopefully without VBA)?

Table2 is a table which has a calculated column and then every other column are table1 columns.

My references in table2 are like this:

calc(table1[column1]) table1[column1] table1[column2] ....

Note: I have tried using @ in the column reference but it did not work.


Solution

  • I resolved it using VBA, so until anyone posts here a VBAless solution here is what you need to do:

    1. Create a named range which we will call range1 on the formulas menu -> name manager

      =OFFSET('table2'!$A$1,0,0,ROWS(table1[#All]),COLUMNS(table2[#All]))

    2. Go to VBA and create the following sub:

      Sub ResizeMyTable()
      
          ThisWorkbook.Sheets("sheet2").ListObjects("table2").Resize [range1]
      
      End Sub
      

    The following logic is up to you, i created a button and did a call ResizeMyTable to update the table.