VBA copy and paste filtered formulas - 1 statement

mocnak

New Member
Joined
Nov 22, 2013
Messages
2
Hello,
I'd like to copy and paste formulas from filtered column, this works for me :

Code:
Sheets(1).Range("A5:C" & LastRow).Copy
Sheets(2).Range("A5:C" & Range("D" & Rows.Count).End(xlUp).Row).PasteSpecial xlPasteFormulas

how can I do it in 1 statement ? when I tried to use
Code:
Sheets(2).Range("A5:C" & Range("D" & Rows.Count).End(xlUp).Row).Formula = Sheets("STAT1").Range("A5:C" & LastRow).Formula

it didn't work as supposed, probably because it didn't handle filtered rows correctly. Any suggestions ?
 

Excel Facts

Repeat Last Command
Pressing F4 adds dollar signs when editing a formula. When not editing, F4 repeats last command.
Hello

See if this produces the desired result:

Code:
Sub OneLine()
Dim d%, lastrow%
lastrow = 10
d = Sheets(2).Range("D" & Rows.Count).End(xlUp).Row

Sheets(1).Range("A5:C" & lastrow).Copy Sheets(2).Range("A5:C" & d)

End Sub
 
Upvote 0
your statement pasted values only, but not formulas. It's good to know it works like this though, I can use it in my other macro's. What is the meaning of '%' at dim statement ?
 
Upvote 0

Forum statistics

Threads
1,216,175
Messages
6,129,310
Members
449,499
Latest member
HockeyBoi

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