Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Function SolvePoly(ParamArray CoeffA() As Variant)
- Dim i As Long
- Dim PArray As Variant
- Dim Num_Coeff As Long
- Dim Res As Variant
- ' Case 1: User enters a single range or array, e.g. =SolvePoly(A1:A5)
- If UBound(CoeffA) = 0 Then
- PArray = GetArray(CoeffA(0))
- ' If coefficients are in a horizontal range, convert to vertical
- If UBound(PArray, 2) > UBound(PArray, 1) Then
- PArray = Transpose1(PArray)
- End If
- Num_Coeff = UBound(PArray, 1)
- ' Case 2: User enters comma-separated arguments, e.g. =SolvePoly(A1,A2,A3)
- Else
- Num_Coeff = UBound(CoeffA) + 1
- ReDim PArray(1 To Num_Coeff, 1 To 1)
- For i = 0 To Num_Coeff - 1
- If IsNumeric(CoeffA(i)) Then
- PArray(i + 1, 1) = CoeffA(i)
- Else
- PArray(i + 1, 1) = CoeffA(i).Value2
- End If
- Next i
- End If
- Select Case Num_Coeff
- Case Is < 3
- SolvePoly = "Num_Coeff must be >= 3"
- Exit Function
- Case Is < 4
- Res = Quadratic(PArray)
- Case 4
- Res = CubicC(PArray)
- Case 5
- Res = Quartic(PArray)
- Case Else
- Res = RPolyJT(PArray)
- End Select
- SolvePoly = WorksheetFunction.Transpose(Res)
- End Function
Advertisement
Add Comment
Please, Sign In to add comment