Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 12-13-2015, 07:46 AM
paik1002 paik1002 is offline Deleting all but one occurrence of text from a selection Windows 7 64bit Deleting all but one occurrence of text from a selection Office 2010 64bit
Advanced Beginner
Deleting all but one occurrence of text from a selection
 
Join Date: Dec 2015
Posts: 63
paik1002 is on a distinguished road
Default 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?
Reply With Quote
  #2  
Old 12-13-2015, 09:40 PM
macropod's Avatar
macropod macropod is offline Deleting all but one occurrence of text from a selection Windows 7 64bit Deleting all but one occurrence of text from a selection Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,963
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

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
For PC macro installation & usage instructions, see: http://www.gmayor.com/installing_macro.htm
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #3  
Old 12-15-2015, 05:13 PM
paik1002 paik1002 is offline Deleting all but one occurrence of text from a selection Windows 7 64bit Deleting all but one occurrence of text from a selection Office 2010 64bit
Advanced Beginner
Deleting all but one occurrence of text from a selection
 
Join Date: Dec 2015
Posts: 63
paik1002 is on a distinguished road
Default

Thank you for the hint. I guess I'll somehow have to try to figure out a solution in another way.
Reply With Quote
  #4  
Old 12-15-2015, 05:17 PM
macropod's Avatar
macropod macropod is offline Deleting all but one occurrence of text from a selection Windows 7 64bit Deleting all but one occurrence of text from a selection Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,963
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Quote:
Originally Posted by paik1002 View Post
I guess I'll somehow have to try to figure out a solution in another way.
Well, you did ask:
Quote:
Originally Posted by paik1002 View Post
Could it be done via word macros?
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
Deleting all but one occurrence of text from a selection Deleting all text except text of a certain font size JustAboutNoon Word VBA 3 10-09-2014 10:21 AM
Deleting all but one occurrence of text from a selection Mysterious bottom row occurrence Ulodesk Word Tables 2 05-26-2013 02:44 PM
Deleting all but one occurrence of text from a selection 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
Deleting all but one occurrence of text from a selection Text Box Selection GugaBFigueiredo Word 1 01-16-2012 09:04 PM
Deleting all but one occurrence of text from a selection Deleting and adding text johnbiggsy Word 1 02-09-2010 08:45 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 10:08 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft