This paper investigates the use of intelligent reflecting surfaces (IRS) to assist cellular communications and radar sensing operations in a communications and sensing setup. The IRS dynamically allocates reflecting elements to simultaneously localize a target and assist a user's communication. To achieve this, we propose a novel optimization framework that jointly addresses beamforming design and IRS element allocation. Specifically, we formulate a Weighted Minimum Mean Square Error (WMMSE)-based approach that iteratively optimizes the transmit and receive beamforming vectors, IRS phase shifts, and element allocation. The allocation mechanism adaptively balances the number of IRS elements dedicated to communication and sensing subsystems by leveraging the signal-to-noise-plus-interference-ratio (SINR) between the two. The proposed solution ensures efficient resource utilization while maintaining performance trade-offs. Numerical results demonstrate significant improvements in both communication and sensing SINRs under varying system parameters.