# Copy Paste Formula

#### vmjan02

##### Well-known Member
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 .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 .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
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 .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 .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 .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``````

Replies
7
Views
121
Replies
6
Views
163
Replies
7
Views
185
Replies
4
Views
218
Replies
3
Views
356

### Forum statistics

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.

### Which adblocker are you using?    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

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