Copy down formula using VBA

Mr2017

Well-known Member
Joined
Nov 28, 2016
Messages
644
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
Hi

I'm trying to copy a formula from cell B1 and paste it into a fixed range of cells (B7:B11).

But it's not working, as expected?

I used this

Range("b1:b1").copy
Range("b7:b11").FillDown

But it didn't work.

Any ideas why?

TIA
 

Excel Facts

Last used cell?
Press Ctrl+End to move to what Excel thinks is the last used cell.
By the way, I'd like to copy the formula only (without the format), then past that to the range.

I tried this, but it didn't work, as expected. Do you know why?

Range("B1").Copy Range("B7:B11").xlPasteFormulas

TIA
 
Upvote 0
That won't work, but either of these will:

Code:
Range("B1").Copy
Range("B7:B11").PasteSpecial xlPasteFormulas

Code:
Range("B7:B11").Formula = Range("B1").Formula
 
Upvote 0
Great - thanks!

I'd tried the first option before, with all the code on one row ie

Range("B1").Copy
Range("B7:B11").PasteSpecial xlPasteFormulas

But it didn't work. It gave me a Compile Error that said "Expected: end of Statement"

Not sure why moving the second half of the code to a new line makes it work?

But thank you for your help!
 
Upvote 0
You can only have it on the same line when using destination and not paste or pastespecial so

Code:
Range("B1").Copy Range("B7")
or
Code:
Range("B1").Copy Destination:= Range("B7")
would work (the first code is shorthand for the second code)
but
Code:
Range("B1").Copy Range("B7").PasteSpecial xlPasteFormulas
wouldn't work, it would need to be
Code:
Range("B1").Copy 
Range("B7").PasteSpecial xlPasteFormulas
 
Last edited:
Upvote 0

Forum statistics

Threads
1,214,846
Messages
6,121,905
Members
449,054
Latest member
luca142

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