Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default 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.


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 620
Default 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.




  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 576
Default 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.




  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default passing a variable as an argument to a function

beautiful, thanks. i knew there had to be a way.

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Passing a range name as an argument to the Index Function Michael Sharpe Excel Discussion (Misc queries) 3 September 5th 12 01:33 PM
Passing a UDF as an argument to a UDF puff Excel Discussion (Misc queries) 3 February 23rd 06 09:46 PM
Passing Variable to LINEST RW Excel Worksheet Functions 5 May 24th 05 07:00 PM
Passing an argument to a quote Zach Excel Programming 1 July 25th 03 04:16 AM
Passing an argument to a quote Zach Excel Programming 1 July 25th 03 01:00 AM


All times are GMT +1. The time now is 05:34 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"