Copy & paste the filtered rows

adamsm

Active Member
Joined
Apr 20, 2010
Messages
444
Hi anyone,

The following code copies filterred data rows from the active workbook sheet and pastes them in the destination workbook if both workbooks are open.

Code:
Sub Copy()
    Dim Rng As Range
    Set Rng = Worksheets("Mem").Columns("D")
    Set Rng = Rng.Resize(65535, 1).Offset(1, 0)
    Set Rng = Rng.Resize(, 3).SpecialCells(xlCellTypeVisible)
    Rng.Copy Workbooks("Book2.xlsx").Worksheets("Mem").Range("D17")
End Sub

How could I make the code to open the Book2.xlsx; paste the copied data and close the workbook with the VBA code without having manually to do that.

Any help on this would be kindly appreciated.
 

Excel Facts

Waterfall charts in Excel?
Office 365 customers have access to Waterfall charts since late 2016. They were added to Excel 2019.
Here is the modification I've made. This modification opens the destination workbook and closes it. But does not copy the data into it.

What may be the reason for this?

Any help on this would be kindly appreciated.

Thanks in advance.

Code:
Sub Copy()
Dim wb As Workbook
' Open the workbook
Set wb = Workbooks.Open("D:\Database\Book2.xlsx")
    Dim Rng As Range
    Dim MemosWks As Worksheet
    Set MemosWks = wb.Worksheets("Mem")
    Set Rng = wb.Worksheets("Mem").Columns("D")
    Set Rng = Rng.Resize(65535, 1).Offset(1, 0)
    Set Rng = Rng.Resize(, 13).SpecialCells(xlCellTypeVisible)
    Rng.Copy Workbooks("Book2.xlsx").Worksheets("Mem").Range("D1")
    ' Save and close the workbook
 wb.Close SaveChanges:=True
End Sub
 
Upvote 0
Hi, Thanks for the reply. Hiow should I reference my source area?

Any help on this would be kindly appreciated.
 
Upvote 0

Forum statistics

Threads
1,224,505
Messages
6,179,153
Members
452,891
Latest member
JUSTOUTOFMYREACH

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