I want to write a function which translates exam points into a grade. If i define the Arrays inside the function it works as expected. But i would like to give the user the option to use his own point/grade structure as a parameter of the function.
I tried this to load an Array from the spreadsheet
This one gives me an Value error in excel.
Function GRADE(Points, ParamArray Pattern())
If IsMissing(Pattern) Then Pattern = Array(90.5, 80, 75, 70, 65, 60, 55, 50, 45, 40, 35)
Grades = Array(1, 1.3, 1.7, 2, 2.3, 2.7, 3, 3.3, 3.7, 4, 5)
For i = LBound(Pattern) To UBound(Pattern)
If Points >= Pattern(i) Then
GRADE = Grades(i)
Exit For
End If
Next i
End Function

=GRADES(A1,B1:B10), or as an array - eg.=GRADES(A1, 95, 90, 85, 80, 75, 65, 55, 50, 45, 40, 35)PatternandGradescontain 11 elements? If not, is there a logic based on which to buildGradesaccording toPatterninput? 2. As suggested above, you can replaceParamArrayparameter with a range (or to an array).GRADE(Points, rngPat As Range)And pass it to the function as "A2:A12". Then, declarePattern As Variantand usePattern = rngPat.Value. And obtaining a 2D array you should useIf Points >= Pattern(i, 1) Then...ParamArray. How are you inputting your Array?=grade(22,50,40,30,20,10,5,2,1)works OK, as does using individual cell references:=grade(22,B1,B2,B3,B4,B5,B6,B7,B8). However, if you are using a multi-cell Range for an argument to Pattern, you need to detect that and then extract each value in the range reference to your pattern array in your code. And, of course, ParamArray can take a variety of inputs. eg `=grade(50,B2:B8,90,95) would also be valid input. You just have to figure out what's what in your code.