Hi,
I have a table cell that contains text from another document. The text can contain many paragraphs and some paragraphs have duplicate paragraphs within the same cell.
I have tried to loop through the text to find and delete all duplicates, but without much success. To illustrate, the following text is an example of the table cell text:
Oranges
Apples
Pears
Grapes
Oranges
Grapes
Peaches
Oranges
Mango
I tried the following code but get a typemismatch error.
Still learning VBA, so would appreciate some help
Private Sub delPara()
Dim myTable As Table
Dim tPara As Paragraph
Dim tRange As Range, tRangeDel As Paragraph
Dim tParaCount As Long
Dim tParaTxt As String
Set myTable = Selection.Tables(1)
Set tRange = myTable.Cell(10, 2).Range
For tParaCount = 1 To tRange.Paragraphs.Count
Set tRangeDel = tRange.Paragraphs(tParaCount)
For Each tPara In Paragraphs
With tRange.Find
.Forward = True
.ClearFormatting
.MatchWholeWord = True
.MatchCase = False
.Wrap = wdFindContinue
.Execute FindText:=tRangeDel
If tRangeDel Then
Selection.Delete
End If
End With
Next tPara
Next tParaCount
End Sub
Regards,
I have a table cell that contains text from another document. The text can contain many paragraphs and some paragraphs have duplicate paragraphs within the same cell.
I have tried to loop through the text to find and delete all duplicates, but without much success. To illustrate, the following text is an example of the table cell text:
Oranges
Apples
Pears
Grapes
Oranges
Grapes
Peaches
Oranges
Mango
I tried the following code but get a typemismatch error.
Still learning VBA, so would appreciate some help
Private Sub delPara()
Dim myTable As Table
Dim tPara As Paragraph
Dim tRange As Range, tRangeDel As Paragraph
Dim tParaCount As Long
Dim tParaTxt As String
Set myTable = Selection.Tables(1)
Set tRange = myTable.Cell(10, 2).Range
For tParaCount = 1 To tRange.Paragraphs.Count
Set tRangeDel = tRange.Paragraphs(tParaCount)
For Each tPara In Paragraphs
With tRange.Find
.Forward = True
.ClearFormatting
.MatchWholeWord = True
.MatchCase = False
.Wrap = wdFindContinue
.Execute FindText:=tRangeDel
If tRangeDel Then
Selection.Delete
End If
End With
Next tPara
Next tParaCount
End Sub
Regards,