Speed up Add Rows VBA

Chewyhairball

Active Member
Joined
Nov 30, 2017
Messages
312
Office Version
  1. 365
Platform
  1. Windows
Hi

I have this bit of code that adds a specified number of rows to table 1 depending on the value in A15.

It works fine but is a bit slow when adding a large number of rows. It is triggered from a button on the sheet.

I was wondering if there is a more efficient way of writing this to make it faster?

thanks

Rory
 

Excel Facts

Which Excel functions can ignore hidden rows?
The SUBTOTAL and AGGREGATE functions ignore hidden rows. AGGREGATE can also exclude error cells and more.
Hi

I have this bit of code that adds a specified number of rows to table 1 depending on the value in A15.

It works fine but is a bit slow when adding a large number of rows. It is triggered from a button on the sheet.

I was wondering if there is a more efficient way of writing this to make it faster?

thanks

Rory
should probably add the code :)

VBA Code:
Dim i As Integer
For i = 1 To Range("A15").Value
ActiveSheet.ListObjects("Table1").ListRows.Add
Next i
 
Upvote 0
See if this is any better.

VBA Code:
With ActiveSheet.ListObjects("Table1")
  .Resize Range(.Range.Resize(.Range.Rows.Count + Range("A15").Value).Address)
End With
 
Upvote 0
See if this is any better.

VBA Code:
With ActiveSheet.ListObjects("Table1")
  .Resize Range(.Range.Resize(.Range.Rows.Count + Range("A15").Value).Address)
End With
Hi
I am getting some kind of runtime overlap error. Possibly due to there being data underneath the table.
 
Upvote 0
I am getting some kind of runtime overlap error.
That is pretty vague. What is the exact error?

Possibly due to there being data underneath the table.
Can you give details if what it is underneath the table and where it is? Unless we can reproduce what you have it is hard to move forward.
 
Upvote 0
Hi

This is the error i am getting

1631176533949.png


Underneath each of the table columns there are columns of typed data, formulas and merged cells.

thanks

Rory
 
Upvote 0
Underneath each of the table columns there are columns of typed data, formulas and merged cells.
So what do your expect to happen to that "typed data, formulas or merged cells" when rows are added to the table above them?
 
Upvote 0
So what do your expect to happen to that "typed data, formulas or merged cells" when rows are added to the table above them?
To move down as new rows are added. Which it does with my current code but it gets slow when dealing with 10 or more rows.
 
Upvote 0
Underneath each of the table columns there are columns of typed data, formulas and merged cells.

To move down as new rows are added. Which it does with my current code but it gets slow when dealing with 10 or more rows.
For me it depends exactly what is below and exactly where it is below but your existing code also errors for me is certain circumstances too.
So I guess my test set-up is not identical to yours - which makes it hard to offer suggestions for improvement.
If you would like it investigated further then perhaps you could provide a sample file (no sensitive data) via a shared link posted here to a file uploaded to DrpBox, OneDrive, Google Drive etc
 
Upvote 0
Hi Peter

I think I will just leave it as it is for just now and maybe come back to it at a later point when I have more time.

Thank you for your help.

Rory
 
Upvote 0

Forum statistics

Threads
1,214,553
Messages
6,120,184
Members
448,949
Latest member
keycalinc

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