If I read that correctly, you're trying to change the value in B2 using the function you've written and inserted into cell P4? If so, no dice.
Functions are able to do any sort of calculation and loop and search and run all over the workbook, but the only thing the function can RETURN to the worksheet is a value into the cell holding the function as a formula.
You will have to construct a normal macro to change the values in your RNG based on a string you enter in P4...or something like that.
So, enter a formula in P4...get an answer in P4, nothing else.
Bookmarks