If I understood the question properly, it has a simple solution. 1. First find a MAX and a MIN value within the range. In this case, 490 and 55. 2. Then, check each value for var1 if var1 < 50 then var1 = MIN else if var1 > 500 then var1 = MAX The point is that, what matters for this solution is only two MIN/MAX values. It is the simplest solution.
... View more