Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 18
Default Defining new function with cell range parameter

I feel really dumb asking this, but 1) I've never had to do it before, and 2)
I really did try it myself using Help!

I want to define a function I can call on a spreadsheet that'll take a cell
range (columns across a row) as input, and then step through the range of
cells in the function doing various things to the individual cells, then
return the result into the cell where the function is called.

In the spreadsheet (say, row 20) I'd expect to have a cell with, say,
"=DBA(J20:T20)" and the function (DBA) would take the 11 cells and loop
through them doing some math; to keep it simple, assume adding them up (I
KNOW there is a function to do that!) and returning the value.

In another row the same function would process the cells from that row.

I'm missing a fundamental concept, e.g., referencing the cell range in the
function and stepping through it. I am really not this dumb!

Can anyone provide a sample as a starter?
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Defining new function with cell range parameter

Put this in a general module

Public function DBA(rng as Range)
Dim tot as Double, cell as Range
tot = 0
for each cell in rng
if isnumeric(cell) then
tot = tot + Cell.Value
end if
Next
DBA = tot
End Function


--
Regards,
Tom Ogilvy


"NormD" wrote in message
...
I feel really dumb asking this, but 1) I've never had to do it before, and

2)
I really did try it myself using Help!

I want to define a function I can call on a spreadsheet that'll take a

cell
range (columns across a row) as input, and then step through the range of
cells in the function doing various things to the individual cells, then
return the result into the cell where the function is called.

In the spreadsheet (say, row 20) I'd expect to have a cell with, say,
"=DBA(J20:T20)" and the function (DBA) would take the 11 cells and loop
through them doing some math; to keep it simple, assume adding them up (I
KNOW there is a function to do that!) and returning the value.

In another row the same function would process the cells from that row.

I'm missing a fundamental concept, e.g., referencing the cell range in the
function and stepping through it. I am really not this dumb!

Can anyone provide a sample as a starter?



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 18
Default Defining new function with cell range parameter

Damned if it doesn't work! First time, too. Thanks, Tom.

"Tom Ogilvy" wrote:

Put this in a general module

Public function DBA(rng as Range)
Dim tot as Double, cell as Range
tot = 0
for each cell in rng
if isnumeric(cell) then
tot = tot + Cell.Value
end if
Next
DBA = tot
End Function


--
Regards,
Tom Ogilvy


"NormD" wrote in message
...
I feel really dumb asking this, but 1) I've never had to do it before, and

2)
I really did try it myself using Help!

I want to define a function I can call on a spreadsheet that'll take a

cell
range (columns across a row) as input, and then step through the range of
cells in the function doing various things to the individual cells, then
return the result into the cell where the function is called.

In the spreadsheet (say, row 20) I'd expect to have a cell with, say,
"=DBA(J20:T20)" and the function (DBA) would take the 11 cells and loop
through them doing some math; to keep it simple, assume adding them up (I
KNOW there is a function to do that!) and returning the value.

In another row the same function would process the cells from that row.

I'm missing a fundamental concept, e.g., referencing the cell range in the
function and stepping through it. I am really not this dumb!

Can anyone provide a sample as a starter?




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
Defining a range using a cell reference jagbabbra Excel Worksheet Functions 5 June 5th 06 01:36 PM
Defining Cell namse after they are used in a function Mariano Excel Worksheet Functions 3 January 4th 06 02:54 PM
Cell contents as the 'lookup value' parameter in HLOOKUP function EMarre Excel Discussion (Misc queries) 3 August 30th 05 03:49 PM
Defining range Edgar[_3_] Excel Programming 2 February 17th 04 02:24 PM
Defining a range Matt Excel Programming 3 January 23rd 04 03:21 PM


All times are GMT +1. The time now is 04:30 AM.

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"