VBA - Change sum cell

ChrisFoster

Active Member
Joined
Jun 21, 2019
Messages
251
Office Version
  1. 365
Platform
  1. Windows
Hi all,

I have some code, as below which does a sum of column L. I have recently had a new column added into a report and now need the below code to sum column M instead of L.
I expect this is an easy thing to change but I don't know which bit relates to the column.

VBA Code:
    ActiveCell.FormulaR1C1 = _
        "=SUMIF('Arrears Breakdown'!C[3],RC[-2],'Arrears Breakdown'!C[9])"

Please can someone tell me how to sum column M instead of L?

Cheers

Chris
 

Excel Facts

Why does 9 mean SUM in SUBTOTAL?
It is because Sum is the 9th alphabetically in Average, Count, CountA, Max, Min, Product, StDev.S, StDev.P, Sum, VAR.S, VAR.P.
How about
VBA Code:
    ActiveCell.FormulaR1C1 = _
        "=SUMIF('Arrears Breakdown'!C[3],RC[-2],'Arrears Breakdown'!C13)"
 
Upvote 0
How about
VBA Code:
    ActiveCell.FormulaR1C1 = _
        "=SUMIF('Arrears Breakdown'!C[3],RC[-2],'Arrears Breakdown'!C13)"
Yes and No. You've helped me sort it though.
My active cell was C2 which I didn't mention in my first post, so I've used the below which has worked.

VBA Code:
    ActiveCell.FormulaR1C1 = _
        "=SUMIF('Arrears Breakdown'!C[3],RC[-2],'Arrears Breakdown'!C10)"

Thanks for your help,

Chris
 
Upvote 0
That is going to sum col J not col M, regardless of what cell the formula is in.
 
Upvote 0
That is going to sum col J not col M, regardless of what cell the formula is in.
It definitely sums column M. It inserts the below formula.

VBA Code:
=SUMIF('Arrears Breakdown'!D:D,E2,'Arrears Breakdown'!M:M)
 
Upvote 0
If the formula you posted is in C2 it will give you
Excel Formula:
=SUMIF('Arrears Breakdown'!F:F,A2,'Arrears Breakdown'!$J:$J)
Regardless of what cell the formula is in it will sum col J as
VBA Code:
'Arrears Breakdown'!C10
is an absolute address to col 10 which is J
 
Upvote 0
If the formula you posted is in C2 it will give you
Excel Formula:
=SUMIF('Arrears Breakdown'!F:F,A2,'Arrears Breakdown'!$J:$J)
Regardless of what cell the formula is in it will sum col J as
VBA Code:
'Arrears Breakdown'!C10
is an absolute address to col 10 which is J
Ah, sorry. I actually used;

VBA Code:
    Range("C2").Select
    ActiveCell.FormulaR1C1 = _
        "=SUMIF('Arrears Breakdown'!C[3],RC[-2],'Arrears Breakdown'!C[10])"

Do the brackets make a difference in C[10]?
 
Upvote 0
Yes they make a very big difference using C10 will return col J regardless regardless of which cell the formula is in, whereas C[10] will return the 10th to the right of the formula (not counting the column with the formula)
 
Upvote 0
Solution
Yes they make a very big difference using C10 will return col J regardless regardless of which cell the formula is in, whereas C[10] will return the 10th to the right of the formula (not counting the column with the formula)
Thanks alot for taking the time to help me with this, it's much appreciated.
 
Upvote 0
You're welcome & thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,215,844
Messages
6,127,252
Members
449,372
Latest member
charlottedv

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