This is going to depend on the exact wording of Y's will. If that will simply said "I leave all my shares of Company C to my grandchildren" they will not get the money, even though it was derived from the proceeds of such shares, but only such actual shares as Y owned when Y died.
At least if Y does still have some shares of C when Y dies. I doubt that Shares never owned by Y, but sold by X, and the proceeds inherited by Y from X would be covered by a bequest of shares in Y's will without any specific number o date being listed. OIf a specific number of share, or those shares owned by Y on a specific date is what is left in Y's will, that would be a different matter.