I am trying to add up the numbers that are in a column, but the column of numbers varies so I'm using the Rows.Count
instead of a set number of rows such as "a1:a5"
. Each time I run this I get the row count (represented as rngcount) but instead of the sum of the cells within the row count (rngcount) I get the row count again.
I was getting an object error (1004)
until I added "a"
to .Range("a" & rngcount)
but I admit I'm not sure why the "a"
is needed as I thought the rngcount
would be all that is needed to Sum
.
So Unfortunately two issues in one post.
Sub simpleSUM()
Dim rng1 As Range
Dim rng2 As Range
Dim rngcount As Integer
Set rng1 = Range("b1") 'This indicates how many cells are in use
Set rng2 = Range("b2") 'This indicates the sum of the cells that are in use
rngcount = cells(Rows.Count, "A").End(xlUp).row
rng1.Value = rngcount
rng2.Value = Application.WorksheetFunction.Sum(ThisWorkbook.Sheets("sheet2").Range("a" & rngcount))
End Sub