Insert formula in last column macro

doriannjeshi

Active Member
Joined
Apr 5, 2015
Messages
337
Office Version
  1. 365
Platform
  1. Windows
Hi,
I need to insert a formula in the last dynamic column in row 2, of a range that starts at A1.
This is what I have static but I need it dynamic last column:

ActiveCell.FormulaR1C1 = "shuma"
Range("AY2").Select
Application.CutCopyMode = False
Selection.FormulaR1C1 = "=SUM(RC[-35]:RC[-1])"
Selection.AutoFill Destination:=Range("AY2:AY" & Range("a" & Rows.Count).End(xlUp).Row)
Range(Selection, Selection.End(xlDown)).Select
Selection.Copy
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
 
this is where I need the formula. the end of a range column. Formula to be copied down the last column.

1732922249359.png
 
Upvote 0

Excel Facts

What do {} around a formula in the formula bar mean?
{Formula} means the formula was entered using Ctrl+Shift+Enter signifying an old-style array formula.
I'll state it again, there is no need to copy anything down (I can't add anymore if you don't get similar results to the below without either an XL2BB of your data or a copy of your workbook so I can see exactly what you have)

With
Book1
ATAUAVAWAXAY
1Header1Header2Header3Header4Header5Header6
23718134819
34618353710
43750332412
54634402823
62919243115
73527491628
85015191745
91518111322
103039292212
113612244439
Sheet8


The code gives me

Book1
ATAUAVAWAXAY
1Header1Header2Header3Header4Header5Header6
23718134819135
34618353710146
43750332412156
54634402823171
62919243115118
73527491628155
85015191745146
9151811132279
103039292212132
113612244439155
Sheet8


With the .Value line commented out (Column BA added manually to show the formulas in Column AY)

Book1
ATAUAVAWAXAYAZBA
1Header1Header2Header3Header4Header5Header6
23718134819135=SUM(P2:AX2)
34618353710146=SUM(P3:AX3)
43750332412156=SUM(P4:AX4)
54634402823171=SUM(P5:AX5)
62919243115118=SUM(P6:AX6)
73527491628155=SUM(P7:AX7)
85015191745146=SUM(P8:AX8)
9151811132279=SUM(P9:AX9)
103039292212132=SUM(P10:AX10)
113612244439155=SUM(P11:AX11)
Sheet8
Cell Formulas
RangeFormula
AY2:AY11AY2=SUM(P2:AX2)
BA2:BA11BA2=FORMULATEXT(AY2)
 
Upvote 0
The formula is dynamic too, meaning it must sum to that point if possible.
When the range is shorter than the formulas range it returns 0 and defeats the purpose

When using a formula that sums a1:a5 , if the range then being dynamic gets shorter a1:a3 it gives me 0
 
Last edited:
Upvote 0
The formula is dynamic too, meaning it must sum to that point if possible.
When the range is shorter than the formulas range it returns 0 and defeats the purpose

When using a formula that sums a1:a5 , if the range then being dynamic gets shorter a1:a3 it gives me 0
Bar your formula sums across columns not down rows as you have it above, so that makes no sense....

Maybe what you want is to fix the start column in the formula (in the below the start column is always column A)
Rich (BB code):
= "=SUM(RC1:RC[-1])"
 
Last edited:
Upvote 0

Forum statistics

Threads
1,224,507
Messages
6,179,176
Members
452,893
Latest member
denay

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