Alternate to loop and copy formulas

JackDanIce

Well-known Member
Joined
Feb 3, 2010
Messages
9,922
Office Version
  1. 365
Platform
  1. Windows
Hi,

I have a header row with a mixture of constants and formulas; using cell formatting to mask formulae (Formula bar visible). This row is 228 columns wide, and has a fixed pattern of 3 columns with formula, 16 columns constant values x 12

The whole header range is named: Main_Formula

I use following to copy formula and apply to rows below but it is slow:
Code:
Sub Apply_Formulas(byref LR as Long)

Dim r as Range
Dim rng as Range: set rng = Range("Main_Formula").Specialcells(xlcelltypeFormulas)

With Application
  .ScreenUpdating = False
  .CalculationMode = xlCalculationManual
End With

For Each r in Rng
  r.Copy
  r.Offset(1).Resize(LR - 1).PasteSpecial xlPasteFormulas
Next r

With Application
  .CutCopyMode = False
  .ScreenUpdating = False
  .CalculationMode = xlCalculationManual
End With

Set rng = Nothing

End Sub

I tried something like:
[/code]
With rng
.Copy
.Resize(LR).PasteSpecial xlPasteFormulas
End With
[/code]
But this gave run time 1004 error, suggesting I'm not defining the paste range correctly?


Any suggestions for faster code?

TIA,
Jack
 

Excel Facts

Does the VLOOKUP table have to be sorted?
No! when you are using an exact match, the VLOOKUP table can be in any order. Best-selling items at the top is actually the best.
You cannot resize non-contiguous ranges. Try
Code:
For Each r In Rng
  r.Resize(Lr).FillDown
Next r
 
Upvote 0
Suspected so, thanks for confirming @Fluff and your suggestion is a little faster than what I had.
 
Last edited:
Upvote 0

Forum statistics

Threads
1,213,550
Messages
6,114,265
Members
448,558
Latest member
aivin

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