![]() |
passing a variable as an argument to a function
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. |
passing a variable as an argument to a function
Drew,
Assuming that rng2 is a range object, then rng1.formula = "=SUM(" & rng2.address & ")" -- HTH ------- Bob Phillips ... looking out across Poole Harbour to the Purbecks "Drew" wrote in message ... 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. |
passing a variable as an argument to a function
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 "Drew" wrote in message ... 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. |
passing a variable as an argument to a function
beautiful, thanks. i knew there had to be a way.
|
All times are GMT +1. The time now is 12:15 PM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com