Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / September 2006

Tip: Looking for answers? Try searching our database.

Find & Replace or Macro - Which is better?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Helen - 08 Sep 2006 21:10 GMT
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
Doug Robbins - Word MVP - 08 Sep 2006 21:24 GMT
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.

Signature

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

> Hello,
>
[quoted text clipped - 11 lines]
>
> Hélène
Helmut Weber - 08 Sep 2006 21:38 GMT
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
Graham Mayor - 09 Sep 2006 07:21 GMT
See my reply in docmanagement. This can still simply be done with replace.

Signature

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

My web site www.gmayor.com
Word MVP web site http://word.mvps.org
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>

> Hi Doug,
>
[quoted text clipped - 9 lines]
>
> Helmut Weber
Helmut Weber - 08 Sep 2006 21:29 GMT
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.

Signature

Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

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


Rate this thread:






 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.