Guest User

solvepoly comma delimited or range input

a guest
Jun 24th, 2026
30
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.21 KB | None | 0 0
  1. Function SolvePoly(ParamArray CoeffA() As Variant)
  2.  
  3. Dim i As Long
  4. Dim PArray As Variant
  5. Dim Num_Coeff As Long
  6. Dim Res As Variant
  7.  
  8. ' Case 1: User enters a single range or array, e.g. =SolvePoly(A1:A5)
  9. If UBound(CoeffA) = 0 Then
  10.  
  11. PArray = GetArray(CoeffA(0))
  12.  
  13. ' If coefficients are in a horizontal range, convert to vertical
  14. If UBound(PArray, 2) > UBound(PArray, 1) Then
  15. PArray = Transpose1(PArray)
  16. End If
  17.  
  18. Num_Coeff = UBound(PArray, 1)
  19.  
  20. ' Case 2: User enters comma-separated arguments, e.g. =SolvePoly(A1,A2,A3)
  21. Else
  22.  
  23. Num_Coeff = UBound(CoeffA) + 1
  24. ReDim PArray(1 To Num_Coeff, 1 To 1)
  25.  
  26. For i = 0 To Num_Coeff - 1
  27. If IsNumeric(CoeffA(i)) Then
  28. PArray(i + 1, 1) = CoeffA(i)
  29. Else
  30. PArray(i + 1, 1) = CoeffA(i).Value2
  31. End If
  32. Next i
  33.  
  34. End If
  35.  
  36. Select Case Num_Coeff
  37. Case Is < 3
  38. SolvePoly = "Num_Coeff must be >= 3"
  39. Exit Function
  40.  
  41. Case Is < 4
  42. Res = Quadratic(PArray)
  43.  
  44. Case 4
  45. Res = CubicC(PArray)
  46.  
  47. Case 5
  48. Res = Quartic(PArray)
  49.  
  50. Case Else
  51. Res = RPolyJT(PArray)
  52. End Select
  53.  
  54. SolvePoly = WorksheetFunction.Transpose(Res)
  55.  
  56. End Function
Advertisement
Add Comment
Please, Sign In to add comment