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. |
|
|
Thread Tools | Display Modes |
#1
|
|||
|
|||
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
|
|||
|
|||
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 | |
|
|