Reply
 
Thread Tools Display Modes
  #1   Report Post  
Posted to microsoft.public.word.docmanagement
giusic
 
Posts: n/a
Default advance find and replace

Hi all,

I would like to replace each .0 value with a 0.0. I have tried a find by
using the following wildcard .([0-9]{1}) but it pick up numbers like 15.2
etc. I only need to to add a zero before those numbers that are less than one.
ANy help would be appreciated.
  #2   Report Post  
Posted to microsoft.public.word.docmanagement
Jay Freedman
 
Posts: n/a
Default advance find and replace

On Thu, 1 Dec 2005 15:15:03 -0800, giusic
wrote:

Hi all,

I would like to replace each .0 value with a 0.0. I have tried a find by
using the following wildcard .([0-9]{1}) but it pick up numbers like 15.2
etc. I only need to to add a zero before those numbers that are less than one.
ANy help would be appreciated.


Change the find expression to

([!0-9])(.[0-9])

and use the replace expression

\10\2

The part of the find expression in the first pair of brackets, using
the ! operator to mean NOT, says "any character that is NOT a digit".
The {1} in your expression isn't necessary, since [0-9] already means
"any one digit". So the whole thing says "any character that is not a
digit, followed by a dot and any digit".

The replacement says "the character that matches the first set of
brackets, then a zero, then the characters that match the second set
of brackets".

This replacement will miss an occurrence at the very start of the
document, since there isn't any non-digit character preceding the dot.
That case is easy to fix manually, though.

--
Regards,
Jay Freedman
Microsoft Word MVP FAQ: http://word.mvps.org
Email cannot be acknowledged; please post all follow-ups to the
newsgroup so all may benefit.
  #3   Report Post  
Posted to microsoft.public.word.docmanagement
giusic
 
Posts: n/a
Default advance find and replace

Thank you for your help! I tried it and it works great. I did forget to
mention (I apologize) that the values I am trying to replace are in a table
and when I use the expression for that purpose it does not work. Perhaps I am
doing something wrong (I am new to this). If you could follow up with me one
more time I would greatly appreciate it.
Thanks a lot again,
Giusi

"Jay Freedman" wrote:

On Thu, 1 Dec 2005 15:15:03 -0800, giusic
wrote:

Hi all,

I would like to replace each .0 value with a 0.0. I have tried a find by
using the following wildcard .([0-9]{1}) but it pick up numbers like 15.2
etc. I only need to to add a zero before those numbers that are less than one.
ANy help would be appreciated.


Change the find expression to

([!0-9])(.[0-9])

and use the replace expression

\10\2

The part of the find expression in the first pair of brackets, using
the ! operator to mean NOT, says "any character that is NOT a digit".
The {1} in your expression isn't necessary, since [0-9] already means
"any one digit". So the whole thing says "any character that is not a
digit, followed by a dot and any digit".

The replacement says "the character that matches the first set of
brackets, then a zero, then the characters that match the second set
of brackets".

This replacement will miss an occurrence at the very start of the
document, since there isn't any non-digit character preceding the dot.
That case is easy to fix manually, though.

--
Regards,
Jay Freedman
Microsoft Word MVP FAQ: http://word.mvps.org
Email cannot be acknowledged; please post all follow-ups to the
newsgroup so all may benefit.

  #4   Report Post  
Posted to microsoft.public.word.docmanagement
Greg
 
Posts: n/a
Default advance find and replace

I think the problem is similiar to what Jay decribes wrt the very start
of the document. In an individual cell there is nothing preceeding the
dot.

Try:
Sub ScratchMacro()
Dim myRng As Range
Dim oCell As Cell
For Each oCell In Selection.Tables(1).Range.Cells
Set myRng = oCell.Range
myRng.End = myRng.End - 1
If myRng.Text = ".0" Then
myRng.Text = "0.0"
End If
Next
End Sub

Jay,

Since I know you will be back and see this, why does the following not
work? I don't understand why the line oCell.Range.End =
oCell.Range.End fails to decrease the range by 1 character:

Sub ScratchMacro2()
Dim oCell As Cell
For Each oCell In Selection.Tables(1).Range.Cells
oCell.Range.End = oCell.Range.End - 1 'This line doesn't cause the
range end value to decrease
If oCell.Range.Text = ".0" Then
oCell.Range.Text = "0.0"
End If
Next
End Sub

  #5   Report Post  
Posted to microsoft.public.word.docmanagement
Greg
 
Posts: n/a
Default advance find and replace

Oops.

I meant I don't understand why the line oCell.Range.End =
oCell.Range.End - 1 fails to decrease the range by 1 character:



  #6   Report Post  
Posted to microsoft.public.word.docmanagement
Greg
 
Posts: n/a
Default advance find and replace

Hmm,

I am starting to convince myself that the issue is that a physical
cells range is what it is and can't be modified. This little bit of
code also fails:
Sub ScratchMacro2()
Dim oCell As Cell
For Each oCell In Selection.Tables(1).Range.Cells
oCell.Range.MoveEnd wdCharacter, -1
oCell.Range.Select 'Selects the whole cell :-(
If oCell.Range.Text = ".0" Then
oCell.Range.Text = "0.0"
End If
Next
End Sub

  #7   Report Post  
Posted to microsoft.public.word.docmanagement
Jay Freedman
 
Posts: n/a
Default advance find and replace

On 2 Dec 2005 07:48:47 -0800, "Greg" wrote:

Hmm,

I am starting to convince myself that the issue is that a physical
cells range is what it is and can't be modified. This little bit of
code also fails:
Sub ScratchMacro2()
Dim oCell As Cell
For Each oCell In Selection.Tables(1).Range.Cells
oCell.Range.MoveEnd wdCharacter, -1
oCell.Range.Select 'Selects the whole cell :-(
If oCell.Range.Text = ".0" Then
oCell.Range.Text = "0.0"
End If
Next
End Sub


Hi Greg,

Yes, that's it exactly. You can't modify the .Start and .End of the
ranges of actual objects in the document, such as a cell or a
paragraph or the whole ActiveDocument. What you can do, though, is
assign that range to a Range object you declare, and then tinker with
that:

Sub ScratchMacro3()
Dim oCell As Cell
Dim oRg As Range
For Each oCell In Selection.Tables(1).Range.Cells
Set oRg = oCell.Range
oRg.MoveEnd wdCharacter, -1
If oRg.Text = ".0" Then
oRg.Text = "0.0"
End If
Next
Set oRg = Nothing
End Sub

--
Regards,
Jay Freedman
Microsoft Word MVP FAQ: http://word.mvps.org
Email cannot be acknowledged; please post all follow-ups to the
newsgroup so all may benefit.
  #8   Report Post  
Posted to microsoft.public.word.docmanagement
Greg
 
Posts: n/a
Default advance find and replace

Yes Jay, that is pretty much what I did in posting a possible solution
to the OPs question earlier. It was while working that out that I was
perplexed by not being able to simple manipulate the cell range.
Thanks for confirming my thoughts.

  #9   Report Post  
Posted to microsoft.public.word.docmanagement
giusic
 
Posts: n/a
Default advance find and replace

Thanks for all your help! The macro worked just fine. I have one more
question: can it be generalized to other numbers e.g., .1; .2; .256; .098
etc.? Again, I am new to both macros and wildcards and I don't know how to
change them myself.
Sincerely,
Giusi


"Greg" wrote:

I think the problem is similiar to what Jay decribes wrt the very start
of the document. In an individual cell there is nothing preceeding the
dot.

Try:
Sub ScratchMacro()
Dim myRng As Range
Dim oCell As Cell
For Each oCell In Selection.Tables(1).Range.Cells
Set myRng = oCell.Range
myRng.End = myRng.End - 1
If myRng.Text = ".0" Then
myRng.Text = "0.0"
End If
Next
End Sub

Jay,

Since I know you will be back and see this, why does the following not
work? I don't understand why the line oCell.Range.End =
oCell.Range.End fails to decrease the range by 1 character:

Sub ScratchMacro2()
Dim oCell As Cell
For Each oCell In Selection.Tables(1).Range.Cells
oCell.Range.End = oCell.Range.End - 1 'This line doesn't cause the
range end value to decrease
If oCell.Range.Text = ".0" Then
oCell.Range.Text = "0.0"
End If
Next
End Sub


  #10   Report Post  
Posted to microsoft.public.word.docmanagement
Greg
 
Posts: n/a
Default advance find and replace

Giusi,

We have abandoned "wildcards" ;-)

Try:

Sub ScratchMacro()
Dim myRng As Range
Dim oCell As Cell
For Each oCell In Selection.Tables(1).Range.Cells
Set myRng = oCell.Range
myRng.End = myRng.End - 1
If Left(myRng.Text, 1) = "." Then
myRng.InsertBefore "0"
End If
Next
End Sub



  #11   Report Post  
Posted to microsoft.public.word.docmanagement
giusic
 
Posts: n/a
Default advance find and replace

It worked! Thanks also for bearing with me...
Giusi


"Greg" wrote:

Giusi,

We have abandoned "wildcards" ;-)

Try:

Sub ScratchMacro()
Dim myRng As Range
Dim oCell As Cell
For Each oCell In Selection.Tables(1).Range.Cells
Set myRng = oCell.Range
myRng.End = myRng.End - 1
If Left(myRng.Text, 1) = "." Then
myRng.InsertBefore "0"
End If
Next
End Sub


Reply
Thread Tools
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
MS Word 2000 Find & Replace Drew Microsoft Word Help 6 November 16th 05 10:29 PM
Find and Replace GREEK symbols in XP, 2K & 97 Jazz Microsoft Word Help 3 April 8th 05 08:13 PM
Find and Replace Michael R New Users 11 January 22nd 05 05:31 PM
Find and Replace anomaly BruceM Microsoft Word Help 7 January 18th 05 05:47 PM
find and replace symbols Tewodaj New Users 8 January 11th 05 02:22 AM


All times are GMT +1. The time now is 12:34 PM.

Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 Microsoft Office Word Forum - WordBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Word"