A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Word » Tables
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

find and replace NUMBERS



 
 
Thread Tools Display Modes
  #1  
Old May 12th, 2007, 04:51 PM posted to microsoft.public.word.tables
Andy
external usenet poster
 
Posts: 941
Default find and replace NUMBERS

hello

i have a two-column table that has text in one column like "Candy - Apples",
then numbers in the second column in the format "28-159a".

What I want to do is do a find and replace such that all the numbers and
dashes in the second column get deleted, leaving behind only the number after
the dash. I can't do a generic wildcard search for *- because it would also
delete the text and - in the first column.

Any ideas? Thank you.
Andrew
  #2  
Old May 12th, 2007, 08:50 PM posted to microsoft.public.word.tables
Helmut Weber
external usenet poster
 
Posts: 131
Default find and replace NUMBERS

Hi Andy,

like this:

Sub Test555()
Dim oTbl As Table
Dim oClm As Column
Dim oCll As Cell
Set oTbl = ActiveDocument.Tables(1)
Set oClm = oTbl.Columns(2)
For Each oCll In oClm.Cells
With oCll.Range.Find
.Text = "[0-9]{1,}-"
.Replacement.Text = ""
.MatchWildcards = True
.Execute Replace:=wdReplaceAll
End With
Next
End Sub

You may as well select the column
and loop through all cells in the selection.

Sub Test555A()
Dim oCll As Cell
For Each oCll In Selection.Cells
With oCll.Range.Find
.Text = "[0-9]{1,}-"
.Replacement.Text = ""
.MatchWildcards = True
.Execute Replace:=wdReplaceAll
End With
Next
End Sub

--
Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Win XP, Office 2003
"red.sys" & Chr$(64) & "t-online.de"



 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT +1. The time now is 12:44 AM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.