MrBartlett
New Member
- Joined
- Jul 22, 2018
- Messages
- 25
Hi all,
I've been referencing this thread: https://www.mrexcel.com/forum/excel-...cted-rows.html
Specifically, this formula:
However, I just want to delete rows of a table, not entire rows of a sheet. I've been looking through Google for at least a good hour, and I can't find a solution for the exact use I have in mind.
Basically, I have a macro that pastes data in a table. But, in some cases, it may be updating a table that already has data, with more rows than are being pasted. For example, a table of 400 rows already has data in A1:A401. My macro pastes 300 rows in A1:A301. I want to delete those extra 100 rows that were not pasted/were already there. However, I just want to delete the table rows, not the sheet rows. Also ,when looking at the sheet after the macro pastes the data, it still has that pasted data selected. So, I figured a script that could remove all table rows underneath (if there is data underneath) would be the most elegant solution.
I've tried various formulas, even clearing table contents and resizing the table before the data is pasted. But, it slows everything down and usually ends up not loading.
Thanks in advance for any insights
I've been referencing this thread: https://www.mrexcel.com/forum/excel-...cted-rows.html
Specifically, this formula:
Rich (BB code):
Sub KeepSelectedRows()
With Selection
OnErrorResumeNext
Rows("1:" & .Row - 1).Delete
Rows(.Row + .Rows.Count & ":" & Rows.Count).Delete
OnErrorGoTo 0
EndWith
EndSub
However, I just want to delete rows of a table, not entire rows of a sheet. I've been looking through Google for at least a good hour, and I can't find a solution for the exact use I have in mind.
Basically, I have a macro that pastes data in a table. But, in some cases, it may be updating a table that already has data, with more rows than are being pasted. For example, a table of 400 rows already has data in A1:A401. My macro pastes 300 rows in A1:A301. I want to delete those extra 100 rows that were not pasted/were already there. However, I just want to delete the table rows, not the sheet rows. Also ,when looking at the sheet after the macro pastes the data, it still has that pasted data selected. So, I figured a script that could remove all table rows underneath (if there is data underneath) would be the most elegant solution.
I've tried various formulas, even clearing table contents and resizing the table before the data is pasted. But, it slows everything down and usually ends up not loading.
Thanks in advance for any insights