Copy Paste Formula

vmjan02

Well-known Member
Joined
Aug 15, 2012
Messages
692
Office Version
  1. 2013
I have formulas In cells I14, K14, L14, M14, N14 and O14 (All the formulas are different).

Is there a code where it will copy the formula till last non blank cell in Column H (in this record starts from H14).

I tried below code, but it is taking lot of time. Is there any other way as the formula is not limited to O14 , it is till CS14
Just need a different way as the execution of code is faster.
VBA Code:
With Worksheets("Intraday -EOD Stats")
    With .Range("I14:I" & .Range("H" & .Rows.Count).End(xlUp).Row)
        .Formula = "=IF($H14<=$D$12,SUMIFS(INDIRECT($A$6&$B$5),INDIRECT($A$6&$C$5),$C14,INDIRECT($A$6&$D$5),$H14))"
        .Value = .Value
        '.NumberFormat = "DD-MM-YYYY"
     End With
End With

With Worksheets("Intraday -EOD Stats")
    With .Range("K14:K" & .Range("H" & .Rows.Count).End(xlUp).Row)
        .Formula = "=SUMIFS(INDIRECT($A$2&K$1),INDIRECT($A$2&$B$2),$C14,INDIRECT($A$2&$C$2),$G14,INDIRECT($A$2&$D$2),$H14)"
        .Value = .Value
        '.NumberFormat = "DD-MM-YYYY"
     End With
End With

With Worksheets("Intraday -EOD Stats")
    With .Range("L14:L" & .Range("H" & .Rows.Count).End(xlUp).Row)
        .Formula = "=SUMIFS(INDIRECT($A$2&L$1),INDIRECT($A$2&$B$2),$C14,INDIRECT($A$2&$C$2),$G14,INDIRECT($A$2&$D$2),$H14)"
        .Value = .Value
        '.NumberFormat = "DD-MM-YYYY"
     End With
End With
 

Excel Facts

Workdays for a market open Mon, Wed, Friday?
Yes! Use "0101011" for the weekend argument in NETWORKDAYS.INTL or WORKDAY.INTL. The 7 digits start on Monday. 1 means it is a weekend.

Herakles

Board Regular
Joined
Jul 5, 2020
Messages
73
Office Version
  1. 365
Platform
  1. Windows
So what is taking the time?

The writing the formula to the cells or the calculation?

Try turning automatic calculation off.

Application.Calculation = xlManual

and then on again at the end of the code

Application.Calculation = xlAutomatic

You will need to calculate the formulas before substituting the range with the result of the formula.

VBA Code:
Application.Calculation = xlManual

With Worksheets("Intraday -EOD Stats")
    With .Range("I14:I" & .Range("H" & .Rows.Count).End(xlUp).Row)
        .Formula = "=IF($H14<=$D$12,SUMIFS(INDIRECT($A$6&$B$5),INDIRECT($A$6&$C$5),$C14,INDIRECT($A$6&$D$5),$H14))"
        .Calculate
        .Value = .Value
        '.NumberFormat = "DD-MM-YYYY"
     End With
End With

With Worksheets("Intraday -EOD Stats")
    With .Range("K14:K" & .Range("H" & .Rows.Count).End(xlUp).Row)
        .Formula = "=SUMIFS(INDIRECT($A$2&K$1),INDIRECT($A$2&$B$2),$C14,INDIRECT($A$2&$C$2),$G14,INDIRECT($A$2&$D$2),$H14)"
        .Calculate
        .Value = .Value
        '.NumberFormat = "DD-MM-YYYY"
     End With
End With

With Worksheets("Intraday -EOD Stats")
    With .Range("L14:L" & .Range("H" & .Rows.Count).End(xlUp).Row)
        .Formula = "=SUMIFS(INDIRECT($A$2&L$1),INDIRECT($A$2&$B$2),$C14,INDIRECT($A$2&$C$2),$G14,INDIRECT($A$2&$D$2),$H14)"
        .Calculate
        .Value = .Value
        '.NumberFormat = "DD-MM-YYYY"
     End With
End With

Application.Calculation = xlAutomatic
 

Forum statistics

Threads
1,144,524
Messages
5,724,839
Members
422,583
Latest member
neomilan

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
Top