Reverse decimal figures

F

FotoArt

hello everyone

I'm using the following code to reverse numerical figures in a word document.
The problem is when it encounters a decimal figure such as 71.6 it would not
reverse. I want all numerical characters to be reversed. So 71.6 should come
out as 6.17.

code:
Sub Aburaa()
Dim myText As Range
Dim myFinalWord As String
Dim aWord As Variant
Set myText = ActiveDocument.Range(Start:=Selection.Start,
End:=Selection.End)
For Each aWord In myText.Words
If IsNumeric(aWord) Then
myFinalWord = StrReverse(aWord)
With Selection.Find
.Text = aWord
.Replacement.Text = myFinalWord
.Format = False
.MatchCase = False

End With
Selection.Find.Execute Replace:=wdReplaceAll

'MsgBox (myFinalWord)
End If
Next aWord
End Sub

Any help would be appreciated.

thanx
ahmed
 
H

Helmut Weber

Hi FotoArt,

maybe this is all you need:

Sub Test56129A()
Dim rDcm As Range
Set rDcm = ActiveDocument.Range
With rDcm.Find
.Text = "[0-9]{1,}.[0-9]{1,}"
.MatchWildcards = True
While .Execute
rDcm.Text = StrReverse(rDcm.Text)
Wend
End With
End Sub

--
Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

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

Russ

To whom it may concern:

Older Win.Word versions and Mac.Word don't have the StrReverse function
builtin.
Francesco Balena wrote this function that I found on the internet:

Function StrReverse(ByVal Text As String) As String

Dim length As Long, index As Long

length = Len(Text)
StrReverse = Space(length)
For index = 1 To length
Mid(StrReverse, length + 1 - index, 1) = Mid(Text, index, 1)
Next

End Function
Hi FotoArt,

maybe this is all you need:

Sub Test56129A()
Dim rDcm As Range
Set rDcm = ActiveDocument.Range
With rDcm.Find
.Text = "[0-9]{1,}.[0-9]{1,}"
.MatchWildcards = True
While .Execute
rDcm.Text = StrReverse(rDcm.Text)
Wend
End With
End Sub
 

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