Can someone help me to fix this error

function rngfilt(x, r)
rngfilt1 = x;
rrngfilt1 =IIf(x > rng,IIf( xn < rng,rng, xn, IIf(xp > rng, rng, xp)));
return rngfilt1;
filt = rngfilt(source, smrng);

error shows as "Error 16 : Too many arguments" and "Error 17: Missing arguments" under rrngfilt1 line

Please help me to fix this error


Iif expects only 3 parameters... 1st is condition, 2nd true value, 3rd false. Your second if has 4 arguments.
I think you have misplaced closing bracket of nested IIf, it should be

rrngfilt1 = IIf(x>rng, IIf(xn<rng, rng, xn), IIf(xp>rng, rng, xp));