Re: Remove text from a range by Tony
Tony
Mon Mar 03 04:13:01 PST 2008
Very interesting. It 'works' in Word 2007, but not in 2003. I didn't know
there had been a change in behaviour.
The Range you define includes cells (5,3), (5,4), (5,5), ..., (5, last) ,
(6,1), (6,2), ..., (6,5)
If you Select it (rng.Select) then just the block (5,3), (5,4), (5,5),
(6,3), (6,4), (6,5) is selected and it is this block that is merged - as you
already know.
After the merge the Range appears to be redefined (in 2003) which is why the
text in the merged cell is not deleted.
If you redefine it yourself you will be able to delete the text.
Sub MergeRangeAndRemoveText2()
Dim rng As Range
Set rng = ActiveDocument.Range _
(Start:=ActiveDocument.Tables(1).Cell(5, 3).Range.Start, _
End:=ActiveDocument.Tables(1).Cell(6, 5).Range.End)
rng.Cells.Merge
Set rng = ActiveDocument.Range _
(Start:=ActiveDocument.Tables(1).Cell(5, 3).Range.Start, _
End:=ActiveDocument.Tables(1).Cell(5, 3).Range.End)
rng.Text = ""
End Sub
--
Enjoy,
Tony
"Harold Druss" <hdruss@comcast.net> wrote in message
news:U4udnePN_65QTVbanZ2dnUVZ_jSdnZ2d@comcast.com...
> Hi
> I need this macro to merge cells and remove all text.
>
> **********************************************
> Sub MergeRangeAndRemoveText()
> Dim rng As Range
>
> Set rng = ActiveDocument.Range _
> (Start:=ActiveDocument.Tables(1).Cell(5, 3).Range.Start, _
> End:=ActiveDocument.Tables(1).Cell(6, 5).Range.End)
>
> rng.Cells.Merge
>
> rng.Text = ""
> End Sub
> **********************************************
>
> The merge works fine, but the text is not removed.
>
> Thanks
> Harold
>