Hello, I am fairly new to vba coding and I am looking for some help.
Ive posted the code im trying to debug or fix. Im not quite sure the proper term, I am actually a mechanical engineering student so ya lol.
The purpose of my code is I have a set of table values with different variables that have values throughout the table. The variables being t, h, u, and so. I have written the code so that the user of the code can go to the formulas tab in excel and pull these table values by using a function through vba coding. The coding will also interpolate values if the value the user wants is not exactly in the table or array I have listed. My problem with my code is when i try and test it, and insert a value into the formula in excel, and it just says error value. I know the value exists because the value is in the array exactly, I have been staring at my code for a while and trying to debug it but I cannot find the issue. I have tried this code on another set of table values and it does work on that one only. I am not sure why that code works and this does not, as they are almost identical except with different array values.

Can someone please point me in the right direction, and possibly explain why my code does not work. I have had no training in vba or have any books on how to code in vba, so I would like to learn from this mistake.
Thank you, have a nice saturday!

Function p1p2_CO2(prop1 As String, val1 As Double, prop2 As String) As Double
Dim ti As Variant
Dim hi As Variant
Dim ui As Variant
Dim soi As Variant
Dim ii As Integer
Dim fi As Double
Dim myans As Double
Dim valmin As Double
Dim valmax As Double

ti = Array(0, 220, 230, 240, 250, 260, 270, 280, 290, 298, _
300, 310, 320, 330, 340, 350, 360, 370, 380, 390, 400, 410, _
420, 430, 440, 450, 460, 470, 480, 490, 500, 510, 520, 530, _
540, 550, 560, 570, 580, 590, 600, 610, 620, 630, 640, 650, _
660, 670, 680, 690, 700, 710, 720, 730, 740, 750, 760, 770, _
780, 790, 800, 810, 820, 830, 840, 850, 860, 870, 880, 890, _
900, 910, 920, 930, 940, 950, 960, 970, 980, 990, 1000, 1020, _
1040, 1060, 1080, 1100, 1120, 1140, 1160, 1180, 1200, 1220, _
1240, 1260, 1280, 1300, 1320, 1340, 1360, 1380, 1400, 1420, _
1440, 1460, 1480, 1500, 1520, 1540, 1560, 1580, 1600, 1620, _
1640, 1660, 1680, 1700, 1720, 1740, 1760, 1780, 1800, 1820, _
1840, 1860, 1880, 1900, 1920, 1940, 1960, 1980, 2000, 2050, _
2100, 2150, 2200, 2250, 2300, 2350, 2400, 2450, 2500, 2550, _
2600, 2650, 2700, 2750, 2800, 2850, 2900, 2950, 3000, 3050, _
3100, 3150, 3200, 3250)

hi = Array(0, 6601, 6938, 7280, 7627, 7979, 8335, 8697, 9063, _
9364, 9431, 9807, 10186, 10570, 10959, 11351, 11748, 12148, _
12552, 12960, 13372, 13787, 14206, 14628, 15054, 15483, 15916, _
16351, 16791, 17232, 17678, 18126, 18576, 19029, 19485, 19945, _
20407, 20870, 21337, 21807, 22280, 22754, 23231, 23709, 24190, _
24674, 25160, 25648, 26138, 26631, 27125, 27622, 28121, 28622, _
29124, 29629, 30135, 30644, 31154, 31665, 32179, 32694, 33212, _
33730, 34251, 34773, 35296, 35821, 36347, 36876, 37405, 37935, _
38467, 39000, 39535, 40070, 40607, 41145, 41685, 42226, 42769, _
43859, 44953, 46051, 47153, 48258, 49369, 50484, 51602, 52724, _
53848, 54977, 56108, 57244, 58381, 59522, 60666, 61813, 62963, _
64116, 65271, 66427, 67586, 68748, 69911, 71078, 72246, 73417, _
74590, 76767, 76944, 78123, 79303, 80486, 81670, 82856, 84043, _
85231, 86420, 87612, 88806, 90000, 91196, 92394, 93593, 94793, _
95995, 97197, 98401, 99606, 100804, 103835, 106864, 109898, _
112939, 115984, 119035, 122091, 125152, 128219, 131290, 134368, _
137449, 140533, 143620, 146713, 149808, 152908, 156009, 159117, _
162226, 165341, 168456, 171576, 174695, 177822)

ui = Array(0, 4772, 5026, 5285, 5548, 5817, 6091, 6369, 6651, _
6885, 6939, 7230, 7526, 7826, 8131, 8439, 8752, 9068, 9392, _
9718, 10046, 10378, 10714, 11053, 11393, 11742, 12091, 12444, _
12800, 13158, 13521, 13885, 14253, 14622, 14996, 15372, 15751, _
16131, 16515, 16902, 17291, 17683, 18076, 18471, 18869, 19270, _
19672, 20078, 20484, 20894, 21305, 21719, 22134, 22552, 22972, _
23393, 23817, 24242, 24669, 25097, 25527, 25959, 26394, 26829, _
27267, 27706, 28125, 28588, 29031, 29476, 29922, 30369, 30818, _
31268, 31719, 32171, 32625, 33081, 33537, 33995, 34455, 35378, _
36306, 37238, 38174, 39112, 40057, 41006, 41957, 42913, 43871, _
44834, 45799, 46768, 47739, 48713, 49691, 50672, 51656, 52643, _
53631, 54621, 55614, 56609, 57606, 58606, 59609, 60613, 61620, _
62630, 63741, 64653, 65668, 66592, 67702, 68721, 69742, 70764, _
71787, 72812, 73840, 74868, 75897, 76929, 77962, 78996, 80031, _
81067, 82105, 83144, 84185, 86791, 89404, 92023, 94648, 97277, _
99912, 102552, 105197, 107849, 110504, 113166, 115832, 118500, _
121172, 123849, 126528, 129212, 131898, 134589, 137283, 139982, _
142681, 145385, 148089, 150801)

soi = Array(0, 202.966, 204.464, 205.92, 207.337, 208.717, _
210.062, 211.376, 212.66, 213.685, 213.915, 215.146, 216.351, _
217.534, 218.694, 219.831, 220.948, 222.044, 223.122, 224.182, _
225.225, 226.25, 227.258, 228.252, 229.23, 230.194, 231.144, _
232.08, 233.004, 233.916, 234.814, 235.7, 236.575, 237.439, _
238.292, 239.135, 239.962, 240.789, 241.602, 242.405, 243.199, _
243.983, 244.758, 245.524, 246.282, 247.032, 247.773, 248.507, _
249.233, 249.952, 250.663, 251.368, 252.065, 252.755, 253.439, _
254.117, 254.787, 255.452, 256.11, 256.762, 257.408, 258.048, _
258.682, 259.311, 259.934, 260.551, 261.164, 261.77, 262.371, _
262.968, 263.559, 264.146, 264.728, 265.304, 265.877, 266.444, _
267.007, 267.566, 268.119, 268.67, 269.215, 270.293, 271.354, _
272.4, 273.43, 274.445, 275.444, 276.43, 277.403, 278.362, _
279.307, 280.238, 281.158, 282.066, 282.962, 283.847, 284.722, _
285.586, 286.439, 287.283, 288.106, 288.934, 289.743, 290.542, _
291.333, 292.114, 292.888, 292.654, 294.411, 295.161, 295.901, _
296.632, 297.356, 298.072, 298.781, 299.482, 300.177, 300.863, _
301.543, 302.271, 302.884, 303.544, 304.198, 304.845, 305.487, _
306.122, 306.751, 307.374, 307.992, 308.604, 309.21, 310.701, _
312.16, 313.589, 314.988, 316.356, 317.695, 319.011, 320.302, _
321.566, 322.808, 324.026, 325.222, 326.396, 327.549, 328.684, _
329.8, 330.896, 331.975, 333.037, 334.084, 335.114, 336.126, _
337.124, 338.109, 339.069)


myans = -5# ' key

prop1 = UCase(prop1)

If (prop1 = "T") Then
 valmin = ti(0)
 valmax = ti(175)
 If (val1 < valmin) Then
  myans = CVErr(xlErrValue)
 ElseIf (val1 > valmax) Then
  myans = CVErr(xlErrValue)
 Else
 ii = Application.Match(val1, ti)
 fi = (val1 - ti(ii - 1)) / (ti(ii) - ti(ii - 1))
 End If
ElseIf (prop1 = "H") Then
 valmin = hi(0)
 valmax = hi(175)
 If (val1 < valmin) Then
  myans = CVErr(xlErrValue)
 ElseIf (val1 > valmax) Then
  myans = CVErr(xlErrValue)
 Else
  ii = Application.Match(val1, hi)
  fi = (val1 - hi(ii - 1)) / (hi(ii) - hi(ii - 1))
 End If
ElseIf (prop1 = "U") Then
 valmin = ui(0)
 valmax = ui(175)
 If (val1 < valmin) Then
  myans = CVErr(xlErrValue)
 ElseIf (val1 > valmax) Then
  myans = CVErr(xlErrValue)
 Else
  ii = Application.Match(val1, ui)
  fi = (val1 - ui(ii - 1)) / (ui(ii) - ui(ii - 1))
 End If
ElseIf (prop1 = "SO") Then
 valmin = soi(0)
 valmax = soi(175)
 If (val1 < valmin) Then
  myans = CVErr(xlErrValue)
 ElseIf (val1 > valmax) Then
  myans = CVErr(xlErrValue)
 Else
  ii = Application.Match(val1, soi)
  fi = (val1 - soi(ii - 1)) / (soi(ii) - soi(ii - 1))
 End If

Else
 myans = CVErr(xlErrValue)
 MsgBox "prop1prop2CO2_A23: what is prop1?"
End If

prop2 = UCase(prop2)
If (Abs(myans + 5) > 0.1) Then
 myans = CVErr(xlErrValue)
ElseIf (prop2 = "T") Then
 myans = ti(ii - 1) + fi * (ti(ii) - ti(ii - 1))
ElseIf (prop2 = "H") Then
 myans = hi(ii - 1) + fi * (hi(ii) - hi(ii - 1))
ElseIf (prop2 = "U") Then
 myans = ui(ii - 1) + fi * (ui(ii) - ui(ii - 1))
ElseIf (prop2 = "SO") Then
 myans = soi(ii - 1) + fi * (soi(ii) - soi(ii - 1))
Else
 myans = CVErr(xlErrValue)
 MsgBox "prop1prop2CO2_A23: what is prop2?"
End If

p1p2_CO2 = myans

End Function