Thanx Bob
I have already modified my VBA code after posting the problem with passing two variables to the function

and that worked well
but the example provided by you seems to be a interesting one and would defnitely try that out.
Thanx a lot for your time and response