简体   繁体   中英

Excel VBA - Sum function

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 :)

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)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM