This should be easy but I keep stumping myself...
I am writing a function for one of my classes to check my work and I can't see to pull a series in...
This is what I have so far but I am pretty sure the Series() part isn't working the way I wanted it to.
(I know there is already a Quartile function but its considered wrong by my professor, hence this macro)
N = total number in series
Q = what % quartile (1st Quartile = 25)
Series() = all the numbers in the series
I want to pull say, A1:A20 into an array, without defining it to just A1:A20
Code:Function QuartileBUS(N, Q, Series()) Dim Hold As Long Dim Hold2 As Integer Dim Hold3 As Long '''' Hold finds what number in the array the first quartile will be found Hold = (N + 1) * (Q / 100) '''' This drops the decimal so it will find a whole number, I figure it cant find placeholder 5.44 in an array Hold2 = Hold '''' This finds the Quartile assuming the array was loaded in which isn't happening Quartile = Series(Hold2) + (Series(Hold2 + 1) - Series(Hold2) * (Hold - Hold2)) End Function
EXAMPLE:
Series to be pulled into an array
116
121
157
192
207
209
209
229
232
236
236
239
245
246
260
264
276
281
283
289
296
307
309
312
317
324
341
353
N = 28 (total number in series above)
Q = 25 (Trying to find the first Quartile)
Series(116,121,157...,341,353)
This is what it should do:
Code:Function QuartileBUS(28, 25,A1:A28) Dim Hold As Long Dim Hold2 As Integer Dim Hold3 As Long Hold = (28 + 1) * (25 / 100) = (29)*(.25) = 7.25 Hold2 = Hold - 7.25 = 7 Quartile = Series(Hold2) + ((Series(Hold2 + 1) - Series(Hold2)) * (Hold - Hold2)) Quartile = Series(7) + ((Series(7+1) - Series(7)) * (7.25-7)) Quartile = 209 + ((229-209)) * (.25)) Quartile = 209 + (20 * .25) Quartile = 209 + 5 Quartile = 214 End Function
I don't know if that is too complicated or explained enough, please post if you don't understand my request =D
Last edited by STr83dgeboi; 01-30-2010 at 05:54 PM.
Ih STr83dgeboimy
Code:Arr = Application.WorksheetFunction.Transpose(Series)
Try something like
Code:option explicit Function QuartileBUS(N, Q, Series) Dim Hold As Long Dim Hold2 As Integer Dim Hold3 As Long Dim Arr Arr = Application.WorksheetFunction.Transpose(Series) '''' Hold finds what number in the array the first quartile will be found Hold = (N + 1) * (Q / 100) '''' This drops the decimal so it will find a whole number, I figure it cant find placeholder 5.44 in an array Hold2 = Hold '''' This finds the Quartile assuming the array was loaded in which isn't happening Quartile = Arr(Hold2) + (Arr(Hold2 + 1) - Arr(Hold2) * (Hold - Hold2)) End Function
regards pike
If the solution helped please donate here to the RSPCA
Sites worth visiting;
J&R Solutions - royUK
AJP Excel Information - Andy Pope
Spreadsheet Toolbox
JBeaucaires Excel Files
VBA for smarties - snb
correction after testing
you can get remove the N bit
and need to comple fuction QuartileBUS=
Code:Option Explicit Function QuartileBUS(Q, Series) Dim Hold As Long Dim Hold2 As Integer Dim Hold3 As Long Dim Arr, N! Arr = Application.WorksheetFunction.Transpose(Series) N = UBound(Arr) '''' Hold finds what number in the array the first quartile will be found Hold = (N + 1) * (Q / 100) '''' This drops the decimal so it will find a whole number, I figure it cant find placeholder 5.44 in an array Hold2 = Hold '''' This finds the Quartile assuming the array was loaded in which isn't happening QuartileBUS = Arr(Hold2) + (Arr(Hold2 + 1) - Arr(Hold2) * (Hold - Hold2)) End Function
regards pike
If the solution helped please donate here to the RSPCA
Sites worth visiting;
J&R Solutions - royUK
AJP Excel Information - Andy Pope
Spreadsheet Toolbox
JBeaucaires Excel Files
VBA for smarties - snb
ok... so that didn't quite help, I don't know if I am doing this wrong or getting another error but I just get a #NAME? error.
Updated Question:
I have this Function
http://i278.photobucket.com/albums/k...oi/example.jpg
What I am having problems with is, how do I get this function to pull the highlighted cells into the array SeriesCode:Function Array(Series()) Array = Series(1)+Series(2) End Function
It does work
with the function
where Q = 25Code:=QuartileBUS(Q, Series)
which you wanted as 1st Quartile
and Series = A1:A25
as the data range
regards pike
If the solution helped please donate here to the RSPCA
Sites worth visiting;
J&R Solutions - royUK
AJP Excel Information - Andy Pope
Spreadsheet Toolbox
JBeaucaires Excel Files
VBA for smarties - snb
Hi STr83dgeboi
Have a look at the attachment
regards pike
If the solution helped please donate here to the RSPCA
Sites worth visiting;
J&R Solutions - royUK
AJP Excel Information - Andy Pope
Spreadsheet Toolbox
JBeaucaires Excel Files
VBA for smarties - snb
Sry for double post, Have a new related problem...
I am trying to turn this from a function into a Form based formula and am having the same but different problem. One button grabs the set of cells like the Function was doing, and the second runs the answer and displays it.
First problem, I am using InputBox to grab the information but I don't know where it is going and how to access it
Second problem, I was trying to get the inputbox to display the information in the text box on the form
Third problem is related to the first one, can't get the answer till I figure out problem one.
I tried searching these forums and the internet with no luck for a solution to the first two problems =/
I attached what I have so far...Code:Private Sub CommandButton1_Click() Dim Hold As Long Dim Hold2 As Integer Dim Hold3 As Long Dim Arr, N! Arr = Application.WorksheetFunction.Transpose(?????) N = UBound(Arr) '''' Hold finds what number in the array the first quartile will be found Hold = (N + 1) * (Q / 100) '''' This drops the decimal so it will find a whole number, I figure it cant find placeholder 5.44 in an array Hold2 = Hold '''' This finds the Quartile assuming the array was loaded in which isn't happening QuartileBUS = Arr(Hold2) + (Arr(Hold2 + 1) - Arr(Hold2) * (Hold - Hold2)) End Sub Private Sub Getdata_Click() Dim InputCells As Range 'Show input box to get range of cells that want to copy Set InputCells = _ Application.InputBox(Prompt:="Select Data", _ Title:="Select Data", Type:=8) Data.Text = InputCells End Sub
Hi STr83dgeboi
Just change the prefix to solved and its best to start a new thread
regards pike
If the solution helped please donate here to the RSPCA
Sites worth visiting;
J&R Solutions - royUK
AJP Excel Information - Andy Pope
Spreadsheet Toolbox
JBeaucaires Excel Files
VBA for smarties - snb
or
Code:Private Sub CommandButton1_Click() Dim Hold As Long Dim Hold2 As Integer Dim Hold3 As Long Dim Arr, Q! Q = InputBox("Select Quartile") Arr = Application.WorksheetFunction.Transpose(Application.InputBox(Prompt:="Select Data", Title:="Select Range", Type:=8)) '''' Hold finds what number in the array the first quartile will be found Hold = (UBound(Arr) + 1) * (Q / 100) '''' This drops the decimal so it will find a whole number, I figure it cant find placeholder 5.44 in an array Hold2 = Hold '''' This finds the Quartile assuming the array was loaded in which isn't happening MsgBox Arr(Hold2) + (Arr(Hold2 + 1) - Arr(Hold2) * (Hold - Hold2)) End Sub
regards pike
If the solution helped please donate here to the RSPCA
Sites worth visiting;
J&R Solutions - royUK
AJP Excel Information - Andy Pope
Spreadsheet Toolbox
JBeaucaires Excel Files
VBA for smarties - snb
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks