0

I'm trying to calculate the sum of my columns (column I). From 1 to the last record in I it has. When I record a macro I get this as output, but this is gibberish to me.

ActiveCell.FormulaR1C1 = "=SUM(R[-11]C:R[-4]C)"

I found another topic and there they said

LastRow = .Range("I" & .rows.Count).End(xlUp).row  
Range("I"&LastRow) = "SUM(I1:I...)"

Except in my case, I can't figure how to enter the lastrow of I in it. All help is welcome :)

1 Answer 1

3

There are two ways of referencing a cell - 'R1C1' and 'A1'. The former works like co-ordinates, with a relative number of rows (R) and cells (C).

The other reference style refers to the cell name on the sheet - B6, F67 etc.

Let's say you want to put your Sum() in cell B1 and LastRow has a value of 6:

ActiveSheet.Range("B1") = "=Sum(I1:I" & LastRow & ")"

Would insert the following function in cell B1:

=SUM(I1:I6)
Sign up to request clarification or add additional context in comments.

2 Comments

Wow ... It seems it makes a big difference when you use spaces. FML
I tried it like this Range("I" & LastRow) = "=SUM(I1:I"&LastRow&")"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.