VBA To Add rows to TABLE based on a cells value

Utradeshow

Well-known Member
Joined
Apr 26, 2004
Messages
807
Office Version
  1. 365
Hi All,

I have a sheet with a TABLE I need a VBA code to add a specified number of rows to the table based on the Value entered in A3 also copying formulas down.

Example: Enter the Value of 20 in Cell A3 and 20 rows added to from row 5 down with formulas also expanding the TABLE SIZE.

TTI Agent Rate Calculator v1.03 - TABLE TEST.xlsm
ABCDEFGHIJKLMN
4LocationStore NameRegionStore TypeCityStZip*AddressZipAgent NameCity State Airport CodeMiles
5#VALUE!#VALUE!#VALUE!#VALUE!#VALUE!#VALUE!
ROLLOUT
Cell Formulas
RangeFormula
I5I5=CDXClosestZip(G5,0,AGENTS!$A$2:$A$165)*1
J5J5=VLOOKUP(I5,AGENTS!A:B,2,FALSE)
K5K5=VLOOKUP(I5,AGENTS!A:C,3,FALSE)
L5L5=VLOOKUP(I5,AGENTS!A:D,4,FALSE)
M5M5=VLOOKUP(I5,AGENTS!A:E,5,FALSE)
N5N5=CDXDistance(G5,I5)
Named Ranges
NameRefers ToCells
AGENTS!_FilterDatabase=AGENTS!$A$1:$R$165J5:M5
 

Excel Facts

Pivot Table Drill Down
Double-click any number in a pivot table to create a new report showing all detail rows that make up that number
How about this for a table named "Table15":

VBA Code:
Sub ResizeTable()

    Dim rng As Range
    Dim tbl As ListObject
  
    Set tbl = ActiveSheet.ListObjects("Table15")
    Set rng = Range("Table15[#All]").Resize(tbl.Range.Rows.Count + Range("A3").Value, tbl.Range.Columns.Count)
  
    tbl.Resize rng

End Sub
 
Upvote 0
Solution
How about this for a table named "Table15":

VBA Code:
Sub ResizeTable()

    Dim rng As Range
    Dim tbl As ListObject
 
    Set tbl = ActiveSheet.ListObjects("Table15")
    Set rng = Range("Table15[#All]").Resize(tbl.Range.Rows.Count + Range("A3").Value, tbl.Range.Columns.Count)
 
    tbl.Resize rng

End Sub

Yes sir! That works amazing! I took it a step further so when I enter a value in cell A4 it will then add that amount of rows

VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)

    Dim LastRow As Long                           '<- added
    If Intersect(Target, Range("A4")) Is Nothing Or Range("A4") = "" Then Exit Sub
    Dim rng As Range
    Dim tbl As ListObject
 
    Set tbl = ActiveSheet.ListObjects("Table15")
    Set rng = Range("Table15[#All]").Resize(tbl.Range.Rows.Count + Range("A4").Value, tbl.Range.Columns.Count)
 
    tbl.Resize rng

End Sub
 
Upvote 0
Great, I am glad it worked for you. I see you are in Florida- me too (South on the East coast)
 
Upvote 0

Forum statistics

Threads
1,224,766
Messages
6,180,846
Members
453,001
Latest member
coulombevin

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