Thanks for your reply:
This code:
Range("G2").Formula = "=SUM(F10:" & Range("F10").End(xlDown).Address
looks to be very close to what I'm attempting, but there seems to be either
quotes or parentheses missing that I can't figure out.
"JLatham" wrote:
David, experiment in VB with the .End method. Examples of its use a
varLastRow = Range("F10").End(xlDown).Row
varLastAddress = Range("F10").End(xlDown).Address
or try this
Range("G2").Formula = "=SUM(F10:" & Range("F10").End(xlDown).Address
the .End takes one of 4 parameters: xlUp, xlDown, xlToLeft or xlToRight
You'll see this kind of thing used a lot also:
longLastUsedRow = Range("A" & Rows.Count).End(xlUp).Row
which will return the last used cell row number in column A. Assuming that
the last cell in column A (A65536 in Excel 2003) is empty, it would return
the row number of the first cell above it that was not empty.
"David B" wrote:
I'm new to VBA Excel and need some help creating some code.
I want to sum two columns of data; the number of rows with data is variable.
First sum=: cell F10 through the end of the range (Which I would normally
select by using shift/ctrl/down arrow). The Sum of this range needs to be in
cell G2.
Second Sum: The second sum needs to be the total of the range that starts 3
rows below (i.e. 2 blank rows) through the end of the data in that column
(Again, I use shift/ctrl/down arrow). This sum needs to be in cell G6.
Am having a tough time writing the code correctly to select the two
ranges....thanks for any hints you can provide.