passing a variable as an argument to a function

  • Thread starter Thread starter Drew
  • Start date Start date
D

Drew

is it possible to use a variable as an argument to a
function? for example: rng1.formula = "=sum(rng2)". im
trying to write a macro that places the sum formula in the
worksheet just below the data. i dont know how many rows
of data there is, so I cant hard code the sum range.
 
Drew,

Assuming that rng2 is a range object, then

rng1.formula = "=SUM(" & rng2.address & ")"
 
Drew,

If your data is in column A

Dim lrow As Long

lrow = Cells(Rows.COUNT, "A").End(xlUp).Row

will determine the lastrow.

than

Cells(lrow+1,1).FormulaR1C1 = "=Sum(R1C1:R" & lrow & "C1)"

should put the sum one row below the last entry in the column.

steve
 
Back
Top