mercredi 1 août 2018

VBA how to evaluate if... elseif... else statement successfully

I have created a macro that I use for bilinear interpolation and it works fine, however I want to generate error outputs i.e. "Error: y and x outside of table range" to do this I have done:

If y < WorksheetFunction.Min(yrng) And x < WorksheetFunction.Min(xrng) Then
    biinterp = "Error: y and x outside of table range"
...and the same for all combinations of y and x both being outside of the y and x range using elseif (the ranges are the data provided in the table that the interpolation is being done with)
ElseIf x < WorksheetFunction.Min(xrng) Then
    biinterp = "Error: x outside of table range (take a min value for y)"
...and the same for all instances where x or y falls above or below the given ranges.
else "my function here"
end if 
end sub

If I enter x or y outside the table range I get a #VALUE! error in the cell, but I can't understand why it won't evaluate the elseif conditions.

Any help would be appreciated

Aucun commentaire:

Enregistrer un commentaire