Resize Table using values in certain cells

Status
Not open for further replies.

excelakos

Board Regular
Joined
Jan 22, 2014
Messages
85
Hi to all.

I ve been searching around but found nothing similar except the code i will paste below (hope to do it properly)
What i look for is to resize a table to specific rows and columns. How many rows and columns will be given by values in specific cells.

So in the following code i managed to find

Code:
Sub ResizeTable()

Dim rng As Range
Dim tbl As ListObject

'Resize Table to 7 rows and 5 columns'
  Set rng = Range("Table1[#All]").Resize(7, 5)
  
  ActiveSheet.ListObjects("Table1").Resize rng
End Sub

Is it possible to replace
Code:
.Resize(7, 5)
with something like
Code:
.Resize("B2", "B3")
with B2, B3 belonging to the same sheet with the table?

Thank you in advance
 

Excel Facts

Bring active cell back into view
Start at A1 and select to A9999 while writing a formula, you can't see A1 anymore. Press Ctrl+Backspace to bring active cell into view.
How about
Code:
Sub ResizeTable()

Dim rng As Range
Dim tbl As ListObject

'Resize Table to 7 rows and 5 columns'
  Set rng = Range("Table1[#All]").Resize(Range("B2").Value, Range("B3").Value)
  Set tbl = ActiveSheet.ListObjects("Table1")
  tbl.Resize rng
End Sub
 
Upvote 0
How about
Code:
Sub ResizeTable()

Dim rng As Range
Dim tbl As ListObject

'Resize Table to 7 rows and 5 columns'
  Set rng = Range("Table1[#All]").Resize(Range("B2").Value, Range("B3").Value)
  Set tbl = ActiveSheet.ListObjects("Table1")
  tbl.Resize rng
End Sub

Dear Fluff
Thank you for your answer. Unfortunately it does not work

Code:
Run-time error '1004':

Application-defined or object-defined error
 
Upvote 0
Do you have a table called table1 on the active sheet?
 
Upvote 0
Do you have a table called table1 on the active sheet?



Hi again..
Probably i was pasting something the bad way...
So now it works...THANK YOU A LOT
Something additional.
1)Is there any way that when i set fewer rows than the existing, data is deleted from those cells which now are left out of the table range?
2)Is there any way that the value i input in the cell reffering to rows to represent actual data cells?I mean we have the header and the totals in the table. Right now if i set value 10 in cell, i get only 8 clear rows.
 
Upvote 0
Status
Not open for further replies.

Forum statistics

Threads
1,223,885
Messages
6,175,183
Members
452,615
Latest member
bogeys2birdies

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top