Virginia's gubernatorial candidates agreed yesterday to a statewide debate on public television next month, but not before Republican Attorney General J. Marshall Coleman got the last -- and sharpest -- word in an exchange with Democrat Lt. Gov. Charles S. Robb.

Robb set the battle of words in a motion when he sent a three-paragraph "Dear Marshall" letter to Coleman's office in Richmond yesterday morning. He told Coleman that his earlier suggestion of weekly debates "this early in the campaign doesn't make much sense to me, [but] the idea of a statewide televised debate reasonably soon after our nominating conventions are completed does make sense."

Both are to be nominated at conventions -- the Democrats, May 29-30 and the Republicans June 5-6 -- both in Virginia Beach.

Yesterday afternoon, Coleman sent a "Dear Chuck" letter to Robb's headquarters saying that a televised debate is a "good idea, anytime, anywhere."

Robb's invitation said that he would hold open the dates of June 24, 26 and 27 for the televised debate.

By nightfall, Bruce Miller, news and public affairs director of Central Virginia Educational Television, said the state's seven public TV stations tentatively had agreed to carry a debate on June 27.

Meanwhile, however, the candidates swapped challenges that appeared to be a warmup for the first of five previously agreed upon debates, 10 days from now in Williamsburg.

"Even though we won't have our programs completely spelled out by that time [next month]." Robb wrote, "it would give interested voters an early opportunity to size us up in a neutral forum, and it might help sharpen the differences between us on major issues."

Coleman, whose quips are a trademark of his campaign style, chided Robb for rejecting his earlier proposal for weekly debates, saying, "I think it is a shame not to give the people a chance to see and hear us side by side, as often as possible."

And he added: "You are right that May and June may seem early to discuss specific programs, but if we are not ready to be governor in May, why should the people assume we would be ready in January?"

Aides to both Robb and Coleman said last night that they favor a format similar to that used in last fall's Reagan-Carter debate sponsored by the League of Women Voters.