Search...
FAQs
Subscribe
Pie
FAQs
Recent topics
Flagged topics
Hot topics
Best topics
Search...
Search within General Computing
Search Coderanch
Advance search
Google search
Register / Login
Post Reply
Bookmark Topic
Watch Topic
New Topic
programming forums
Java
Mobile
Certification
Databases
Caching
Books
Engineering
Micro Controllers
OS
Languages
Paradigms
IDEs
Build Tools
Frameworks
Application Servers
Open Source
This Site
Careers
Other
Pie Elite
all forums
this forum made possible by our volunteer staff, including ...
Marshals:
Tim Cooke
Campbell Ritchie
paul wheaton
Ron McLeod
Devaka Cooray
Sheriffs:
Jeanne Boyarsky
Liutauras Vilda
Paul Clapham
Saloon Keepers:
Tim Holloway
Carey Brown
Piet Souris
Bartenders:
Forum:
General Computing
excel VBA question
Jackie Wang
Ranch Hand
Posts: 315
posted 19 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
ColumnA ColumnB
#N/A=myaverage(A1:A5)
#N/A=myaverage(A1:A5)
3=myaverage(A1:A5)
5=myaverage(A1:A5)
0=myaverage(A1:A5)
Function name: MyAverage
Input: the array of the above 5 cell (I hope i can be dynamic)
output: average of the non #NA cell. In this case 2.3333
Can anyone shed some light to write this little macro
Sameer Jamal
Ranch Hand
Posts: 1871
posted 19 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Public Function GetAverage(ParamArray CellRanges() As Variant) As Double Dim Cel As Range Dim MyAvg As Double Dim Myranges() As Range Dim Results() As Double Dim I As Integer ReDim Myranges(UBound(CellRanges)) ReDim Results((UBound(CellRanges))) For I = LBound(CellRanges) To UBound(CellRanges) Set Myranges(I) = Range(CellRanges(I)) For Each Cel In Myranges(I) Results(I) = Results(I) + Cel.Value Next Results(I) = Results(I) / Myranges(I).Cells.Count Next For I = LBound(Results) To UBound(Results) If CStr(Results(I)) <> "#N/A" Then MyAvg = MyAvg + Results(I) End If Next GetAverage = MyAvg End Function Private Function Average(MyRange As Range) As Double Dim Cel As Range Dim Result As Double For Each Cel In MyRange Result = Result + Cel.Value Next Average = Result / MyRange.Cells.Count End Function
reply
reply
Bookmark Topic
Watch Topic
New Topic
Boost this thread!
Similar Threads
== and equals in String Class
Nearest neighbour...How to find it?
can some one help me in this Prob plz
permutation combination problem
Whether the flow of a process is dynamic ?
More...