Copying from one sheet and pasting to the next empty row is no longer working

berm007

New Member
Joined
Feb 28, 2022
Messages
1
Office Version
  1. 2016
Platform
  1. Windows
Hi guys and gals... I am having a nightmare and need some help!

I am trying to filter my data by a specific column (in this case Column 'D') and then copy the filtered data to another worksheet in the same workbook.

I have basically copied and pasted some VBA script I used on another project that did this exact task and the code worked there but for some reason will not work here! The debugger is pointing me towards the final 2 lines in the code but I have no idea what's going wrong... Any help would be amazing!!! I'm using office 2016 if that helps...

VBA Code:
Worksheets("Sheet1").Range("D:D").AutoFilter _
    Field:=4, _
    Criteria1:="AMEX", _
    Operator:=xlAnd

Worksheets("Sheet1").UsedRange.Columns("A:C").Offset(1).Copy _
    Destination:=Worksheets("Sheet2").Range("A" & Rows.Count).End(xlUp).Offset(1)
 

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
You didn't say what the actual error message was, but my guess is that Excel thinks Sheet1's used range goes all the way to the bottom of the worksheet. If that was the case then
UsedRange.Columns("A:C").Offset(1)
would be trying to copy something that was off the bottom of the worksheet.

Add this line above that code and see what it tells you when the code runs.

Rich (BB code):
MsgBox Sheets("Sheet1").UsedRange.Rows.Count
Worksheets("Sheet1").Range("D:D").AutoFilter _
    Field:=4, _
    Criteria1:="AMEX", _
    Operator:=xlAnd

Worksheets("Sheet1").UsedRange.Columns("A:C").Offset(1).Copy _
    Destination:=Worksheets("Sheet2").Range("A" & Rows.Count).End(xlUp).Offset(1)

If that does not help you solve the problem then tell us what the actual error message you got was.
 
Upvote 0

Forum statistics

Threads
1,215,356
Messages
6,124,475
Members
449,164
Latest member
Monchichi

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