Paste into Table then delete Rows below last pasted Value

hmltnangel

Board Regular
Joined
Aug 25, 2010
Messages
213
Office Version
  1. 2016
Platform
  1. Windows
Afternoon All :)

Cant seem to find anythjing I could use for this, so thought I could ask on here. Hopefully someone has something hiding away that would work.

I copy from one table - to another and paste into "Table2" as text every day. The amount of table rows varies from day to day. Is there a piece of VBA that would allow me to paste in and auto delete any table rows that did not get data pasted into them?

thanks
 

Some videos you may like

Excel Facts

What is the last column in Excel?
Excel columns run from A to Z, AA to AZ, AAA to XFD. The last column is XFD.

maabadi

Well-known Member
Joined
Oct 22, 2012
Messages
1,643
Office Version
  1. 2019
  2. 2016
Platform
  1. Windows
This is one Example, If your table2 start from row 1, Delete all rows except header and first row after that.
VBA Code:
Sub PasteDatatoTable()
Dim Sh1 As Worksheet, Sh2 As Worksheet, Lr1 As Long, i As Long, Lr2 As Long
Set Sh1 = Sheets("Sheet1")
Set Sh2 = Sheets("Sheet2")
Lr1 = Sh1.Range("A" & Rows.Count).End(xlUp).Row
Lr2 = Sh2.Range("A" & Rows.Count).End(xlUp).Row
Sh1.Range("A3:D" & Lr1).EntireRow.Delete
Sh2.Range("A1:D" & Lr2).Copy Sh1.Range("A2")

End Sub
 

Watch MrExcel Video

Forum statistics

Threads
1,127,768
Messages
5,626,778
Members
416,202
Latest member
donya ba

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
Top