#1   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 8
Default VBA

My friend gave me the following as a solution to a question.

Public Function CjsAverage(ParamArray DataRanges()) As Double

Dim rDataRange As Range
Dim rCell As Range
Dim dTotal As Double
Dim iCount As Long
Dim i As Long

For i = LBound(DataRanges) To UBound(DataRanges)
For Each rCell In DataRanges(i).Cells
If Not IsError(rCell.Value) Then
If IsNumeric(rCell.Value) Then
dTotal = dTotal + rCell.Value
iCount = iCount + 1
End If
End If
Next rCell
Next i

CjsAverage = dTotal / iCount

I am to save it in a module in VBA but when I go to the Excel view and "run"
macros, I do not find it listed. How do I find it in Excel view? My friend
has left for the weekend and is unavailable to assist me further with this
quandary.
  #2   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 11,058
Default VBA

Because its a Function and not a Sub, it doesn't show up in

Tools Macro Macros...

and you don't call it with a mouse click. Just enter it in a worksheet cell
like =SUM(), etc.
--
Gary's Student


"whispagirl" wrote:

My friend gave me the following as a solution to a question.

Public Function CjsAverage(ParamArray DataRanges()) As Double

Dim rDataRange As Range
Dim rCell As Range
Dim dTotal As Double
Dim iCount As Long
Dim i As Long

For i = LBound(DataRanges) To UBound(DataRanges)
For Each rCell In DataRanges(i).Cells
If Not IsError(rCell.Value) Then
If IsNumeric(rCell.Value) Then
dTotal = dTotal + rCell.Value
iCount = iCount + 1
End If
End If
Next rCell
Next i

CjsAverage = dTotal / iCount

I am to save it in a module in VBA but when I go to the Excel view and "run"
macros, I do not find it listed. How do I find it in Excel view? My friend
has left for the weekend and is unavailable to assist me further with this
quandary.

  #3   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 3,365
Default VBA

To elaborate on what Gary''s Student said -
use it like you would a regular Excel function in a cell, like this:
=CjsAverage(B1:B99)


"whispagirl" wrote:

My friend gave me the following as a solution to a question.

Public Function CjsAverage(ParamArray DataRanges()) As Double

Dim rDataRange As Range
Dim rCell As Range
Dim dTotal As Double
Dim iCount As Long
Dim i As Long

For i = LBound(DataRanges) To UBound(DataRanges)
For Each rCell In DataRanges(i).Cells
If Not IsError(rCell.Value) Then
If IsNumeric(rCell.Value) Then
dTotal = dTotal + rCell.Value
iCount = iCount + 1
End If
End If
Next rCell
Next i

CjsAverage = dTotal / iCount

I am to save it in a module in VBA but when I go to the Excel view and "run"
macros, I do not find it listed. How do I find it in Excel view? My friend
has left for the weekend and is unavailable to assist me further with this
quandary.

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



All times are GMT +1. The time now is 01:02 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"