#1
|
|||
|
|||
Deleting all but one occurrence of text from a selection
The selection is: apple banana grape apple orange apple banana banana apple apple
Q1: I'd like delete all but one occurence of apple from the above selection. Q2: And do the same, this time including wildcards for search and replace(e.g. \1 \2 \3 ...). Could it be done via word macros? |
#2
|
||||
|
||||
This really isn't a job for Find/Replace; rather, it calls for a macro like:
Code:
Sub Demo() Application.ScreenUpdating = False Dim strTxt As String, i As Long, j As Long With Selection For i = 1 To .Words.Count For j = .Words.Count To i + 1 Step -1 If .Words(i) = .Words(j) Then .Words(j).Delete End If Next Next End With Application.ScreenUpdating = True End Sub
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#3
|
|||
|
|||
Thank you for the hint. I guess I'll somehow have to try to figure out a solution in another way.
|
#4
|
||||
|
||||
Quote:
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Deleting all text except text of a certain font size | JustAboutNoon | Word VBA | 3 | 10-09-2014 10:21 AM |
Mysterious bottom row occurrence | Ulodesk | Word Tables | 2 | 05-26-2013 02:44 PM |
Selection of all Text for a specific page in word is spanning selection across pages | ramsgarla | Word VBA | 9 | 12-05-2012 03:23 AM |
Text Box Selection | GugaBFigueiredo | Word | 1 | 01-16-2012 09:04 PM |
Deleting and adding text | johnbiggsy | Word | 1 | 02-09-2010 08:45 PM |