Auto Formula

ExcelRoy

Well-known Member
Joined
Oct 2, 2006
Messages
2,540
Office Version
  1. 365
Platform
  1. Windows
Hi,

I am looking to set up an auto formula macro which i can get to work fine

But the following part of the formula is what i am having trouble with

Cells(i, "H").Formula = "=IF(P1_F_T_0" & x & "="""","""",SUM(H" & a & ":H" & b & ")))"

What i need is

"a" to show 13, "b" to show 23 on the first formula
"a" to show 175, "b" to show 185 on the second formula
"a" to show 337, "b" to show 347 on the third formula
"a" to show 499, "b" to show 509 on the fourth formula

etc, etc

Here's the complete code


Code:
Sub AutoFormulaEntry()
x = 1
For i = 26 To 16064 Step 162
Cells(i, "H").Formula = "=IF(P1_F_T_0" & x & "="""","""",SUM(H" & a & ":H" & b & ")))"
x = x + 1
Next i
End Sub

Thanks
 

Excel Facts

Whats the difference between CONCAT and CONCATENATE?
The newer CONCAT function can reference a range of cells. =CONCATENATE(A1,A2,A3,A4,A5) becomes =CONCAT(A1:A5)
try
Code:
Sub AutoFormulaEntry()
Dim x As Long, i As Long
x = 1
For i = 26 To 16064 Step 162
    Cells(i, "H").FormulaR1C1 = "=IF(P1_F_T_0" & x & "="""","""",SUM(R[-13]C:R[-3]C))"
    x = x + 1
Next i
End Sub
 
Upvote 0
Hi ExcelRoy,

Another option:


Code:
Sub AutoFormulaEntry()
x = 1
For i = 26 To 16064 Step 162
Cells(i, "H").Formula = "=IF(P1_F_T_0" & x & "="""","""",SUM(H" & (i - 13) & ":H" & (i - 3) & ")))"
x = x + 1
Next i
End Sub
Hope this helps.

Regards.
 
Upvote 0
Now thats what im talking about!

Both works better, i think i will go with the cgcamal one as i understand it more!

Thanks cgcamal

Thanks Jonmo
 
Upvote 0
Hi,

Actually cgcamal's version doesn't work, so its Jonmo's version for me!

Thanks
 
Upvote 0
Hi,
Actually cgcamal's version doesn't work, so its Jonmo's version for me!
Thanks

That probably doesn't work for the same reason your original posted didn't work...
One too many ) at the end

Cells(i, "H").Formula = "=IF(P1_F_T_0" & x & "="""","""",SUM(H" & (i - 13) & ":H" & (i - 3) & ")))"
should be
Cells(i, "H").Formula = "=IF(P1_F_T_0" & x & "="""","""",SUM(H" & (i - 13) & ":H" & (i - 3) & "))"
 
Upvote 0
Yup, that'll be the reason.

Sorry guys, but thanks for the solutions
 
Upvote 0

Forum statistics

Threads
1,224,603
Messages
6,179,850
Members
452,948
Latest member
UsmanAli786

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