VBA copy and pasting into different tab at the end of the last empty row

cynthi263

New Member
Joined
May 14, 2019
Messages
19
i currently have this:

Set wb = ThisWorkbook

Set sh1 = wb.Sheets("Query")
Set sh2 = wb.Sheets("Credits")
Set sh3 = wb.Sheets("Duplicate")
Set sh4 = wb.Sheets("Rev Rvsd")
Set sh5 = wb.Sheets("Rebills")
Set sh6 = wb.Sheets("Pivot")
Set sh7 = wb.Sheets("Work")
Set sh8 = wb.Sheets("Removed")
Set sh9 = wb.Sheets("Validation")
Set sh10 = wb.Sheets("Excluded")

sh5.Range("C2:AW65000").SpecialCells(xlCellTypeVisible).Copy
With sh10
sh10.Cells(1).End(x1up).Row .PasteSpecial xlPasteAll
End With
sh5.Range("C2:AW65000").Offset(1, 0).EntireRow.Delete

i am getting an error on the line in red - i want it to paste the info from sh.5 into sh.10 at the end of the current data that is already there starting with column A.
 

Excel Facts

Create a chart in one keystroke
Select the data and press Alt+F1 to insert a default chart. You can change the default chart to any chart type
It should be xlUp not x1Up (ie lower case L).
 
Upvote 0
Ok, how about
VBA Code:
sh5.Range("C2:AW65000").SpecialCells(xlCellTypeVisible).Copy sh10.Range("A" & Rows.Count).End(xlUp).Offset(1)
sh5.Range("C2:AW65000").Offset(1, 0).EntireRow.Delete
 
Upvote 0
Ok, how about
VBA Code:
sh5.Range("C2:AW65000").SpecialCells(xlCellTypeVisible).Copy sh10.Range("A" & Rows.Count).End(xlUp).Offset(1)
sh5.Range("C2:AW65000").Offset(1, 0).EntireRow.Delete
that didn't work either. it gave me an error stating invalid use of property.
 
Upvote 0
Dim sh1 As Worksheet, sh2 As Worksheet, sh3 As Worksheet, sh4 As Worksheet, sh5 As Worksheet, sh6 As Worksheet, sh7 As Worksheet, sh8 As Worksheet, sh9 As Worksheet, sh10 As Worksheet
Dim wb As Workbook, wb2 As Workbook
Dim CopyRange As Range
Dim RangeRev As Range
Dim lastrow As Long, lastrow2 As Long, lastrow3 As Long
Dim fill As Range, fill2 As Range

'wb=Current Month Template
Set wb = ThisWorkbook

Set sh1 = wb.Sheets("Query")
Set sh2 = wb.Sheets("Credits")
Set sh3 = wb.Sheets("Duplicate")
Set sh4 = wb.Sheets("Rev Rvsd")
Set sh5 = wb.Sheets("Rebills")
Set sh6 = wb.Sheets("Pivot")
Set sh7 = wb.Sheets("Work")
Set sh8 = wb.Sheets("Removed")
Set sh9 = wb.Sheets("Validation")
Set sh10 = wb.Sheets("Excluded")

lastrow = sh2.Cells(Rows.Count, "B").End(xlUp).Row
Set fill = sh2.Range("AG3:AG" & lastrow)

lastrow2 = sh5.Cells(Rows.Count, "D").End(xlUp).Row
Set fill2 = sh5.Range("AI2:AI" & lastrow2)

lastrow3 = sh10.Cells(Rows.Count, "A").End(xlUp).Row

here is where i defined the sheets, then below is where the copy function is on one of the sh.

I'd like the code to look at another sheet (rebills) and essentially do the same thing we did on the (credits) but since there will already be info on sh.10 - i need it to paste the last row after the info from the credit's tab has been pasted. I dont have an issue with the credit's one, it's the rebills one that i have issues with the pasting line. (in purple)

credits
'Filter by excluded products and cut and paste into the excluded tab credits


sh2.Range("A2:BA65000").AutoFilter Field:=44, Criteria1:=Array( _
"USRGRP", "FORMS", "KIA", "FRT", "UPS", "TAX", "BMX", "DOCSCN", "ENCRYP", "FORMS", "FRT", "IBMSS", "IDSCAN", "INVSTR", "ISERES", "NCIPHR", "OS400", "OTHER", "PRNTRS", "PSERES", "PWRSYS", "RKUNTS", "SCANER", "SECRTY", "SERVER", "SFTWR", "SLVPK", "SORTRS", "SPTLNE", "STORAG", "SWMA", "SWSUB", "UNISYS", "UPS", "XSERES"), Operator:=xlFilterValues

sh2.Range("A3:AU65000").SpecialCells(xlCellTypeVisible).Copy
With sh10
sh10.Cells(2, 1).PasteSpecial xlPasteAll
End With
sh2.Range("A3:AU65000").Offset(1, 0).EntireRow.Delete

sh2.Range("A2:BA65000").AutoFilter Field:=44

rebills

'Filter by excluded products and cut and paste into the excluded tab rebills


sh5.Range("A2:AW65000").AutoFilter Field:=46, Criteria1:=Array( _
"USRGRP", "FORMS", "KIA", "FRT", "UPS", "TAX", "BMX", "DOCSCN", "ENCRYP", "FORMS", "FRT", "IBMSS", "IDSCAN", "INVSTR", "ISERES", "NCIPHR", "OS400", "OTHER", "PRNTRS", "PSERES", "PWRSYS", "RKUNTS", "SCANER", "SECRTY", "SERVER", "SFTWR", "SLVPK", "SORTRS", "SPTLNE", "STORAG", "SWMA", "SWSUB", "UNISYS", "UPS", "XSERES"), Operator:=xlFilterValues

sh5.Range("C2:AW65000").SpecialCells(xlCellTypeVisible).Copy
sh10.Range("A" & lastrow3).selection.PasteSpecial xlPasteAll
sh5.Range("C2:AW65000").Offset(1, 0).EntireRow.Delete

sh5.Range("A2:BA65000").AutoFilter Field:=46
 
Upvote 0
That is not the code that I suggested, it should be
VBA Code:
sh5.Range("C2:AW65000").SpecialCells(xlCellTypeVisible).Copy sh10.Range("A" & Rows.Count).End(xlUp).Offset(1)
which is all one line not two.
 
Upvote 0
in red - the macro won't go past that. when it did, it had deleted the info already in SH10 that was pasted from the credits.

rebills

'Filter by excluded products and cut and paste into the excluded tab rebills


sh5.Range("A2:AW65000").AutoFilter Field:=46, Criteria1:=Array( _
"USRGRP", "FORMS", "KIA", "FRT", "UPS", "TAX", "BMX", "DOCSCN", "ENCRYP", "FORMS", "FRT", "IBMSS", "IDSCAN", "INVSTR", "ISERES", "NCIPHR", "OS400", "OTHER", "PRNTRS", "PSERES", "PWRSYS", "RKUNTS", "SCANER", "SECRTY", "SERVER", "SFTWR", "SLVPK", "SORTRS", "SPTLNE", "STORAG", "SWMA", "SWSUB", "UNISYS", "UPS", "XSERES"), Operator:=xlFilterValues

sh5.Range("C2:AW65000").SpecialCells(xlCellTypeVisible).Copy
sh10.Range("A" & lastrow3).selection.PasteSpecial xlPasteAll
sh5.Range("C2:AW65000").Offset(1, 0).EntireRow.Delete

sh5.Range("A2:BA65000").AutoFilter Field:=46
 
Upvote 0
Not sure if you saw post#8 as we posted about the same time
 
Upvote 0

Forum statistics

Threads
1,223,704
Messages
6,173,984
Members
452,540
Latest member
haasro02

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