Find & Replace or Macro - Which is better?

H

Helen

Hello,

I tried finding a solution by myself, but no-can-do. How can I tell Word to:

a) Find the dollar sign ($) and;
b) Place it at the end of the amount instead of the beginning, i.e., change
$10,000 for 10 000 $.

It also has to be preceded by a hard space.

Thank you!

Hélène
 
D

Doug Robbins - Word MVP

It can be done with a Wildcard Replace, using

($)([0-9,]{1,})

in the Find what control and with

\2^s$

in the Replace with control

If you also want to replace the thousands separator with a space then run a
second Wildcard Replace using

(,)([0-9]{3})

in the Find what control and

[space]\2

in the Replace with control

Press the spacebar where the [space] appears above.

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP
 
H

Helmut Weber

Hi again,

try this:

Sub French()
Dim rDcm As Range
Dim rTmp As Range
Dim sTmp As String
Dim pos1 As Long
Dim pos2 As Long
Set rDcm = ActiveDocument.Range
Set rTmp = selection.Range
With rDcm.Find
.Text = "$[0-9]{1,}"
.MatchWildcards = True
While .Execute
rDcm.Select ' only for testing [F8]
pos1 = rDcm.start
rTmp.start = pos1
rTmp.End = ActiveDocument.Range.End
With rTmp.Find
.Text = "[!0-9,.$]"
.MatchWildcards = True
If .Execute Then
rTmp.Select ' only for testing [F8]
pos2 = rTmp.End - 1
rTmp.start = pos1
rTmp.End = pos2
rTmp.Select ' only for testing [F8]
sTmp = rTmp.Text
sTmp = Replace(sTmp, ",", Chr(160))
' non breaking spaces everywhere !
sTmp = Replace(sTmp, ".", ",")
sTmp = Right(sTmp, Len(sTmp) - 1)
sTmp = sTmp & Chr(160) & "$"
rTmp.Text = sTmp
End If
End With
Wend
End With
End Sub

There might be some redundancy in the code.
Just the way it is with the first attempt.

The code searches for a $-sign followed by one or more digits.
It remembers the postition, where where "$[0-9]{1,}" was found.
It then searches for a character not equal to
on of those 0 til 9 , . $
It remembers that position (pos2).
It sets a range from pos1 to pos2 -1.
The contents of that range are processed
in the variable stmp.
Kommas are replaced by non-breaking spaces chr(160).
The period is replaced by a komma.
The leading $-sign is cut off.
A non-breaking space and a $-sign are added at the end of stmp.
The range defined by pos1 and pos2 is set to stmp.
Voilá.

Lines marked by ' only for testing [F8]
can be deleted if everything is working alright.

--
Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

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

Helmut Weber

Hi Doug,

sure, right.

I had discussed this with Helen in docmanagement before,
and Helen has to process numbers like:

$10,000.88 -- $1,234.88 -- $123,898,999.00

If it came to $12,123,898,999.00
Helen might be a very important person. ;-)

Helmut Weber
 
G

Graham Mayor

See my reply in docmanagement. This can still simply be done with replace.

--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 

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