find and replace NUMBERS

A

Andy

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
 
H

Helmut Weber

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"
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top