Group: microsoft.public.word.vba.general
From: "Stefan Blom"
Date: Monday, March 03, 2008 5:49 AM
Subject: Re: Remove text from a range

Delete the text first, and then merge the cells:

Sub MergeRangeAndRemoveText()

Dim rng As Range
Dim i As Long, j As Long

For i = 5 To 6
For j = 3 To 5
ActiveDocument.Tables(1).Cell(Row:=i, Column:=j). _
Range.Text = ""
Next j
Next i

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

End Sub

FWIW, working with ranges and table columns is tricky. The following code,
used on a document that has a table with at least six rows and more than
five columns, illustrates the problem:

Set rng = ActiveDocument.Range _
(Start:=ActiveDocument.Tables(1).Cell(5, 3).Range.Start, _
End:=ActiveDocument.Tables(1).Cell(6, 5).Range.End)

rng.Select

rng.Font.Bold = True
Selection.Font.Name = "Courier New"

Note which cells will be bold and which will be in Courier New!

--
Stefan Blom
Microsoft Word MVP


"Harold Druss" 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
>






Safety Articles | Usenet Groups | Usenet News | Bluegrass