F/R to make numbers and units consistent

S

Steve

I've received parts document contributions from a variety of authors. As you
would expect, they have all used different ways to represent numbers and
units. My challenge is to unify all the numbers and units so they follow a
consistent pattern. For example, one author wrote $200B, $10M, and 15$/sq m.
Notice there is no space between the number and the units (e.g., the 200 and
"B" are next to each other as are the 10 and "M"). I'd prefer to have $200
B, $10 M and 15 $/sq m.

I think I need to use wild-cards to find any number followed by a "B", but I
can't figure out how to replace with the same number and a " B" (space-B).
In other words, "$200B" would become "$200 B" and "15$/sq m" would become
"15 $/sqm".

I've got a general macro that does a lot of clean-up and would like to add
this F/R to my macro so the cleanup is fully automated.

Thanks in advance,
Steve
 
H

Helmut Weber

Hi Steve,
like this, and note, that I have omitted for brevity
some search options you can take care of yourself:
Sub Makro10()
Selection.HomeKey Unit:=wdStory
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = "($[0-9]{1,})([BM])"
.Replacement.Text = "\1 \2"
.MatchWildcards = True
End With
Selection.Find.Execute Replace:=wdReplaceAll
End Sub
Sub Makro11()
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = "([0-9]{1,})($)"
.Replacement.Text = "\1 \2"
.Wrap = wdFindContinue
.MatchWildcards = True
End With
Selection.Find.Execute Replace:=wdReplaceAll
End Sub
 
S

Steve

Thanks very much, Helmut. I struggled a bit this morning and came up with
something similar:

.Text = "([0-9]{1,}) B"
.Replacement.Text = "\1^sB" ' put non-breaking space between
number and "B"

I then repeated this to find the "M"

.Text = "([0-9]{1,}) M"
.Replacement.Text = "\1^sM"

I didn't think of combining the B & M into another search expression.

Steve
 

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