Copy sheet INCLUDING FORMULAS with Autofilter

ohuffman7

New Member
Joined
Jan 18, 2022
Messages
3
Office Version
  1. 2010
Platform
  1. Windows
Trying to get my data to copy into a new sheet but i need the formulas to be copied as well. Any ideas?? Currently this just copies the cells' values.

Sub MoveData()
Sheet6.[Y1:Y1901].AutoFilter 1, "PASS"
Sheet6.[A1:Y1901].Copy Sheet2.[A1]
Sheet6.[A1].AutoFilter
End Sub
 

Excel Facts

Control Word Wrap
Press Alt+Enter to move to a new row in a cell. Lets you control where the words wrap.
Hi ohuffman7,

Welcome to MrExcel!!

You will need to use PasteSpecial when copying the filtered (visible) range which cannot be done on a one liner like you have. See how this goes:

VBA Code:
Option Explicit
Sub MoveData()

    Sheet6.[Y1:Y1901].AutoFilter 1, "PASS"
    Sheet6.[A1:Y1901].SpecialCells(xlCellTypeVisible).Copy
    Sheet2.[A1].PasteSpecial xlPasteFormulas
    Sheet6.[A1].AutoFilter

End Sub

Regards,

Robert
 
Upvote 0
Solution
This...

VBA Code:
Sub MoveData()
    Sheet6.[Y1:Y1901].AutoFilter 1, "PASS"
    Sheet6.[A1:Y1901].Copy
    Sheet2.[A1].PasteSpecial xlPasteAll
    Sheet6.[A1].AutoFilter
End Sub
 
Upvote 0
Hi ohuffman7,

Welcome to MrExcel!!

You will need to use PasteSpecial when copying the filtered (visible) range which cannot be done on a one liner like you have. See how this goes:

VBA Code:
Option Explicit
Sub MoveData()

    Sheet6.[Y1:Y1901].AutoFilter 1, "PASS"
    Sheet6.[A1:Y1901].SpecialCells(xlCellTypeVisible).Copy
    Sheet2.[A1].PasteSpecial xlPasteFormulas
    Sheet6.[A1].AutoFilter

End Sub

Regards,

Robert
Thank you Robert!!! This was so helpful.
 
Upvote 0
This...

VBA Code:
Sub MoveData()
    Sheet6.[Y1:Y1901].AutoFilter 1, "PASS"
    Sheet6.[A1:Y1901].Copy
    Sheet2.[A1].PasteSpecial xlPasteAll
    Sheet6.[A1].AutoFilter
End Sub
Thank you so much!!
 
Upvote 0

Forum statistics

Threads
1,214,413
Messages
6,119,372
Members
448,888
Latest member
Arle8907

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