putting count of the number of rows at the bottom

G

Guest

I have the following lines in a macro that puts the sums of number in column
J at the bottom of all the rows. I want to put the count of rows on the same
row as the sums for column J, but in column D. How do I do that?

lastrow = Cells(Rows.Count, "J").End(xlUp).Row
Cells(lastrow + 1, "J") = Application.Sum(Range(Cells(2, "J"),
Cells(lastrow, "J")))
 
M

macropod

Hi lpdarspe,

I thought you wanted the value on the last row.

If you want it on the next row (which now becomes the last row), try:
..Cells(lastrow + 1, 4).Value = lastrow
or, if you want to count the new last row:
..Cells(lastrow + 1, 4).Value = lastrow

Cheers
 
G

Guest

macropod,

That got it!

Thanks!

macropod said:
Hi lpdarspe,

I thought you wanted the value on the last row.

If you want it on the next row (which now becomes the last row), try:
..Cells(lastrow + 1, 4).Value = lastrow
or, if you want to count the new last row:
..Cells(lastrow + 1, 4).Value = lastrow

Cheers
 
M

macropod

Oops - the second one should have been:
..Cells(lastrow + 1, 4).Value = lastrow + 1
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top