VBA Function For "Mean" Using Array As Argument
Sep 8, 2005
I am trying to create a function in VBA (possibly an add-in in the future) to
calculate Relative Standard Deviation (RSD). I would like to be able to use
an equation such as: =RSD(values), where the values are cell references (a
variable quantity) chosen by the user.
To do this I've copied scripts for "Mean" and "StdDev", then wrote a small
function for RSD that calls those two. When I try to implement RSD in the
worksheet (or even just Mean), the cell returns an error: #VALUE! I think
the problem has something to do with the Arr() variable used as the argument,
as I've tried some simpler functions with array arguments and can't get them
to work, but using standard non-array arguments works fine. I can write a
subroutine that calls the functions and displays the correct result, but I
would like to be able to use RSD as a typical function in my worksheet.
If I could get Mean to work properly, I should be able to apply that
knowledge to StdDev and RSD. The text for Mean is listed below. I've tried
quite a few modifications to try to make it work, so if someone could get it
to work and reply with the correct function text (or with another function
that performs similarly), I'd appreciate it. Thanks.
Function Mean(Arr() As Single)
Dim Sum As Single
Dim i As Integer
Sum = 0
For i = 1 To UBound(Arr)
Sum = Sum + Arr(i)
Next i
Mean = Sum / UBound(Arr)
End Function
View 14 Replies
ADVERTISEMENT
Dec 28, 2013
Can we use an array like {1;3;4;5} as Row or Column argument in INDEX function? Like shown below
=INDEX($A$1:$E$10,0,{1;3;2;4;5}) OR =INDEX($A$1:$E$5,{1;2;4;5;3},0)
View 9 Replies
View Related
Jan 26, 2010
I need to figure out how to match three values on the "source info.xls" file attached to the "PFG FILE.xls" that is also attached. In column A in the "Source info.xls" file the formula will need to match the yellow column, then the green column, then the red column. keep in mind that the attached files are just a small subset of data. The "PFG File.XLS" is actually 150K rows long.
View 5 Replies
View Related
Nov 2, 2009
I'm getting an error that I'm not quite clear about. I'm essentially using a fuction that Mr. Leith Ross provided here: http://www.excelforum.com/excel-prog...xt-source.html to grab text from a web page. I want to create 100 rows of data based on the array housing that data using the SPLIT function.
View 2 Replies
View Related
Feb 3, 2009
This Thread describes a function that I've found incredibly useful to reset the "last used cell" in a worksheet. I use this function a lot, and I would like to make a macro out of it. I have a menu-item added in my excel that runs the macro;
View 3 Replies
View Related
Jul 17, 2008
I want to include a sheet name as an argument to a UDF - is there a way to do it without enclosing it in ""s?
I've been playing around a bit, but however I dim the argument in the UDF, it doesn't seem to like a string without ""s as an argument - creating a NAME error. Luke (lasw10) tells me that this is because it thinks it's a variable, which makes sense. But I want there to be a way, because it feels counter-intuitive to have to use ""s, and the kind of thing that most users would forget to do.
View 9 Replies
View Related
May 26, 2006
In my current worksheet, IF(0 = "CS") returns TRUE, but on any other file this same argument returns FALSE. The cells' formats are both general. I want it to be FALSE.
View 2 Replies
View Related
Jul 6, 2006
I would like to write a function that enhances conditional formatting capabilities in this way: suppose that cell(4,5) contains a number that can be 0 to 5
in the adiacent cell(4,6) i want to put a function that:
1) write "NO DATA", "HIGH", "GOOD", "MODERATE", "POOR", "BAD" depending on that value
2)Choose color font depending on value
3)Choose color background depending on value
I wrote this piece of
Public Function StatusResponse(AdiacentCell As Range) As String
Dim thisStatus As String
Dim ThisFontColor As Integer
Dim ThisbkColor As Integer
Select Case AdiacentCell.Cells(1, 1)
Case Is = 0
ThisbkColor = 2
ThisFontColor = 1
StatusResponse = "NO DATA"............
View 2 Replies
View Related
Aug 25, 2006
I am trying to copy or edit a cell thats has the following formula (see below), I keep getting this message "You cannot change part of an Array!"
=If(ROW($A2:$A8)-ROW(A2)+1>COUNT(W2:W8),"",INDEX($A:$A,SMALL(W2:W8,ROW(INDIRECT("1:"&ROWS(A2:A8))))))
View 5 Replies
View Related
May 2, 2008
I having trouble with an intermediate step filling of an array based on the input range data and polynomial degree. The values calculated (xsum and xysum) for the array (F in the code) are accurate, but the function returns #VALUE for all elements.
Function poly_fit(ByVal Xdata As Range, Ydata As Range) As Variant
Dim a As Integer, b As Integer, c As Integer
Dim deg As Integer, num_pt As Integer
Dim Xs() As Variant, Ys As Variant
Dim F() As Variant, XY() As Variant, coef() As Variant
Dim xsum As Variant, xysum As Variant
Xs = WorksheetFunction.Transpose(Xdata)
Ys = WorksheetFunction.Transpose(Ydata)
If UBound(Xs) UBound(Ys) Then
MsgBox "You don't have the same number of X's and Y's"
End
View 9 Replies
View Related
Dec 13, 2009
=if(I3>0,"",H3) This statement is in cell "J3". What do I need to add to make "J3" not clear when a value is added to "I3
View 2 Replies
View Related
Dec 14, 2006
I work as a data manager at a bear meat factory*. We use a numeric code which refers to the tenderness of each bears flesh and prior to harvest -I often have to sort that data based on the numeric code.
Excel has issues with screening numbers in Autofilter. You can not filter "begins with" or "ends with" if the data is numeric. For Example:
This same problem does not exist in "Find"
Since I seem to be relying on Autofilter for my queries, and it is possible to create a function similar to autofilter using the properly working "find" feature -I was wondering if anyone had already written a function that returns a range and functions similarly to autofilter?
View 9 Replies
View Related
May 6, 2008
I have below code apearing couple times in my macro and I'd like to make a variable.
Plese see belowe
Workbooks.OpenText Filename:= _
"S:ReportsMy ReportsGuidefilename20080430", Origin:=xlMSDOS, _ ' filename should be another variable as it referes to different files
StartRow:=1, DataType:=xlDelimited, TextQualifier:=xlDoubleQuote, _
ConsecutiveDelimiter:=False, Tab:=True, Semicolon:=False, Comma:=True, _
Space:=False, Other:=False, FieldInfo:= Array(Array(1, 1), Array(2, 1), Array( _
3, 1), Array(4, 1), Array(5, 1), Array(6, 1), Array(7, 1), Array(8, 1), Array(9, 1), Array(10 _
, 1), Array(11, 1), Array(12, 1), Array(13, 1), Array(14, 1), Array(15, 1), Array(16, 1), _
Array(17, 1), Array(18, 1), Array(19, 1), Array(20, 1), Array(21, 1), Array(22, 1), Array( _
23, 1), Array(24, 1), Array(25, 1), Array(26, 1), Array(27, 1), Array(28, 1)), _
TrailingMinusNumbers:=True
View 3 Replies
View Related
Jul 1, 2009
Cell A1: International Studies Academy (P) 9-12
Cell A2: Public
Is there a way that I can get Cell A2 to fill red when cell A2="Public" and A1 contains "(P)"?. I can't seem to get a formula to work yet.
View 2 Replies
View Related
Sep 25, 2008
how to create a function argument containing my own defined formula?
View 9 Replies
View Related
May 23, 2008
formula to calculate the commission based on 9 cases each case is subjected to 4 differant arguments.
here is the formula for the first case (the answer if true 1.4) & the last case( if all the casses are fails it should show 0.6) u will find it in cell K5
=IF(AND(E5>=20,H5=1,I5>=80,J5>=80),1.4,0.6)
this is only 1 case HOW can i calculate it basd on 9 casses??
View 10 Replies
View Related
Jan 23, 2008
When I try a MATCH function, I substituted the range through the ADDRESS function. But, it returns #VALUE error. When I manually typed the same range address, it produces the results. I've been behind this more than 8 hours still I can resist the heat on my cool head! But, I thought you coolest head guys need some heat to warm up for to-day's challenge.
View 9 Replies
View Related
Feb 17, 2010
I have created a workbook for keeping records of all maintenance to vehicles in our fleet.
I have a sheet called Vehicle maintenance input:
& then another 10 sheets with the vehicle callsign.
So
Sheet 1 :- Input all data sheet
Sheet 2 :- Y4
Sheet 3 :- Y7
& so on.
I need a formulae that will copy multiple info to the relevant sheets, I have found a way of copying multiple info, with the formulae below, but I can't get it to work if there is more than 1 sheet.
=IF(ISERROR(INDEX($A$1:$B$24,SMALL(IF($A$1:$A$24=C$27,ROW($A$1:$A$24)),ROW(2:2)),2)),"",INDEX($A$1:$B$24,SMALL(IF($A$1:$A$24=C$27,ROW($A$1:$A$24)),ROW(2:2)),2))
View 9 Replies
View Related
Sep 16, 2009
I have an attached file and I am trying to build a VBA function to calculate total values. First row is "RollingTime" and for example if I am trying to calculate the "Total" value. For "RollingTime" = 2 it should be
RollingTime(2)*Percentage(2)+RollingTime (1)*(1-Percentage(1))*Percentage(2)+RollingTime(0)*(1-Percentage(0)*(1-Percentage(1))*Percentage(2)
Which is 109732508*0,3 + 1017508995*(1-0,2)*0,3+1587172158*(1-0,1)*(1-0,2)*0,3
And here is the code I have tried to produce:
View 10 Replies
View Related
Sep 12, 2006
In the code bellow I would like to automate a if function until the 1st emptycell in the row 7 of my spreadsheet.
In my IF function, I would like to refer to a fix cell ("B1") while the other argument is in the same column as the function but two rows bellow.
My problem is that I don't figure out how to refer to a fix cell with the syntax I would like to use t run the macro.
I think it's more clear when you'll see the code
Sub Face2face()
Range("B5").Activate
Do
If ActiveCell.FormulaR1C1="=If(R[2]C>=Range("B2"),Range("B2"),R[2]C)"
ActiveCell.Offset(0, 1).Select
Loop Until IsEmpty(ActiveCell.Offset(-1, 0))
End Sub
View 8 Replies
View Related
Dec 20, 2008
.370.375.376reject
.370.375.369reject
.370.375.372accept
I have 4 cells in a row as noted above. (I have listed the 3 examples of the results I need for clarification if needed) The first 2 cells are not variable and the 3rd cell is a variable number. The fourth cell is where I want a statement of either "accept: or "reject".
If cell #3 is less than cell #1 I want it to "reject", If cell #3 is greater than cell#2 I also want it to "reject" but if the number is eual to or between cell #2 and #3 I want the results to be "accept". So the purple numbers are fixed, the black numbers are variable and the red and green numbers are the results. So if I can get the "accept" and "reject" to work I would also like them to turn "green" and or "red" depending on the results.
View 3 Replies
View Related
Jun 25, 2013
When I step-through my code below, it always opens the first file in the directory "C:Pyramid Files", but when it comes back to the Pyramid Files sub after fully processing the first file via various other subs, the VB Editor apparently doesn't like something about this line: StrFile = Dir(), since it quits after "snapping-back" to the previous sub Initialize(). I have also tried StrFile = Dir, but that doesn't work either. I did Dim Strfile in the General Declarations. When I set Watches for Dir and Dir(), I get the value "Invalid procedure call or argument" for both, as if the directory function lost the value. I can't determine why this is happening.
VB:
Dim WSM As Worksheet, WSB As Worksheet, WS1 As Worksheet, [U]StrFile As String[/U], StrDirectory As String, ClientCode As String
Dim Filename As String, LastRowb As Long, LastColB As Integer, LastRow1 As Integer, NextRowC As Integer, x As Integer, y As Integer
[Code] .......
View 4 Replies
View Related
Feb 26, 2014
Need to use CountIFs formula to evaluate multiple conditions in the same column. Here is the formula I tried. It works for Resolved but returns 0 when i try to add Duplicate.
=COUNTIFS('P12 Source'!H:H,A18,'P12 Source'!F:F,"Resolved,duplicate")
Also used this formula with success by referencing a cell that had "Resolved" in it but when I tried to add another cell with "Duplicate" it again returned 0.
=COUNTIFS('P12 Source'!$H:$H,A19,'P12 Source'!$F:$F,'P12 Source'!$F$75)
View 8 Replies
View Related
Dec 3, 2012
I have the following problem: I have this formula, that works correctly:
=SOMMA.SE('[myfile_12112012.xlsx]RIEPILOGO'!$C$2:$C$12;E1;'[myfile_12112012.xlsx]RIEPILOGO'!$B$2:$B$12)
I wish I could read the name of the file (myfile_12112012.xlsx) or, alternatively, all of the function's first argument (('[myfile_12112012.xlsx]RIEPILOGO'!$C$2:$C$12) from a separate cell.
I tried this:
SOMMA.SE = (C2, E1, '[myfile_12112012.xlsx] ERROR SUMMARY'! $ B $ 2: $ B $ 12)
putting in the cell C2 the string:
'[myfile_12112012.xlsx]RIEPILOGO'!$C$2:$C$12
In this way, however, the formula does not work.
How can I read and evaluate correctly the first argument from the cell c2?
View 2 Replies
View Related
May 6, 2009
I have made my own excel function that my users needs every day. it works just fine, however if you do not know the required argument for this function, you couldn't use it. How can i prompt my users for the right order of the argument when they type the function in excel?. example is when you type the Function "=left(" you will be prompted by excel of the correct arguments.
View 3 Replies
View Related
Jun 27, 2006
I have a function in a cell triggered on the value returned by a DDE link in another cell.
e.g. cell A1 contains =function1(A2) and cell A2 contains
=ADVFN|NYSE_CAT!CUR
function1 is triggered each time the DDE link updates regardless of whether the result returned has changed or not. How do I prevent function1 being triggered if the returned value has not changed?
View 9 Replies
View Related
Aug 30, 2012
This error message in line vpp:
Invalid procedure call or argument
Code:
Function fn1(ByVal a, ByVal i, ByVal e, ByVal N, ByVal w, ByVal ta)
Pi = Application.WorksheetFunction.Pi
mhu = 398600
vpp = (mhu / Math.Sqr(mhu * a * (1 - e ^ 2))) * (-Math.Sin(ta * Pi / 180))
fn1 = 2 * vpp
End Function
View 9 Replies
View Related
Jul 2, 2013
When I attempt to send a spreadsheet using a German version of Excel, the following formula does NOT work properly.
=ZELLE("adresse",C14)
The function gets translated into =CELL("adresse", C14), and what I need is, obviously, = CELL("address",C14). The argument does not get translated.
View 1 Replies
View Related
Apr 17, 2009
the task for the code below is to search through rows in array and check if there's no "text" in it like user inputed in box. But it always shows that there's no such email,i can't figure out the mistake, Maybe the problem is in the type the InputBox returns? But i've tried entering type := 2 (text),dunno what else i can do...I've also tried using p = InputBox("Please,eneter email!").
View 2 Replies
View Related
Mar 13, 2007
= LOOKUP(L4,' Speed Charts'!A4:A73,'Speed Charts'!B4:B73)
I want to filldown this formula, but the comparison range ( sheet 2, columns A & B, rows 4-73) never changes. how can accomplish this so when i use ctrl-d, only L4 updates (to L5, L6, L7, etc..), but the range remains the same?
by default, filldown tool updates the range to A5:A74, A6:A75, A7:A76, etc
if it helps i'm using this forumla to:
1) take a value (L4)
2) find this value in the first range (somewhere in sheet 2 column A)
3) enter the corresponding value (sheet 2 column b, same row)
View 3 Replies
View Related