excel - Public function using a Select Case statement spits out #VALUE! errors -
based off of statement in book, calculating whichever pv=nrt value choose select case letter.
public function athing(solvefor string, v1 single, v2 single, v3 single, v4 single) variant dim p single dim v single dim n single dim r single dim t single select case solvefor case "p" n = v1 r = v2 t = v3 v = v4 athing = n * r * t / v case "v" n = v1 r = v2 t = v3 p = v4 athing = n * r * t / p case "n" p = v1 v = v2 r = v3 t = v4 athing= p * v / (r * t) case "r" p = v1 v = v2 n = v3 t = v4 athing = p * v / (n * t) case "t" p = v1 v = v2 n = v3 r = v4 athing = p * v / (n * r) case else athing = "can't find varialbe solve for, again" end select end function
if put number in select case's place, returns else case. if place case's letter inside, returns #value! error, meaning somehow have incorrect input somewhere.
the function located inside module, shouldn't issue.
is there obvious?
the solution, replacing letters of case "" numbers. excel dislikes having letters , numbers inside functions, dunno why. using 0-4 represent pv=nrt appear in equation.
public function athing(solvefor string, v1 single, v2 single, v3 single, v4 single) variant dim p single dim v single dim n single dim r single dim t single select case solvefor case "0" n = v1 r = v2 t = v3 v = v4 athing = n * r * t / v case "1" n = v1 r = v2 t = v3 p = v4 athing = n * r * t / p case "2" p = v1 v = v2 r = v3 t = v4 athing= p * v / (r * t) case "3" p = v1 v = v2 n = v3 t = v4 athing = p * v / (n * t) case "4" p = v1 v = v2 n = v3 r = v4 athing = p * v / (n * r) case else athing = "can't find variable solve for, again" end select end function
Comments
Post a Comment