Reply
 
Thread Tools Display Modes
  #1   Report Post  
Sudhir_Gawade Sudhir_Gawade is offline
Junior Member
 
Posts: 3
Question Add 0 before decimal point through VBA

Hi,

In my MS Word document, there are about 50 pages. I need to add "0" where decimal value is in this format .25 or any Number. I need VBA code.

I have tried with below, but it is time consuming is there other way of doing same.

Sub a()

With ActiveDocument
For i = 1 To .Words.Count

If .Words(i).Text = "." Then

If IsNumeric(.Words(i).Text & .Words(i + 1).Text) And .Words(i - 1).Text "0" Then

.Words(i).Text = "0" & .Words(i).Text
i = i + 2
End If
End If
Next
End With

End Sub

Thanks in advance

Regards,
Sudhir.
  #2   Report Post  
Posted to microsoft.public.word.formatting.longdocs
Stefan Blom[_3_] Stefan Blom[_3_] is offline
external usenet poster
 
Posts: 6,897
Default Add 0 before decimal point through VBA

A wildcard search should do the trick. There might be more efficient
ways, but here's one attempt:

"Find what": ([!0-9])(.)([0-9])

"Replace with": 0\2\3

(Note that I have entered a space before the zero in the "Replace with"
box.)

Test it on a *copy* of your document.

Stefan Blom
Microsoft Word MVP





On 2012-06-05 06:54, Sudhir_Gawade wrote:
Hi,

In my MS Word document, there are about 50 pages. I need to add "0"
where decimal value is in this format .25 or any Number. I need VBA
code.

I have tried with below, but it is time consuming is there other way of
doing same.

Sub a()

With ActiveDocument
For i = 1 To .Words.Count

If .Words(i).Text = "." Then

If IsNumeric(.Words(i).Text & .Words(i + 1).Text) And .Words(i - 1).Text
"0" Then

.Words(i).Text = "0" & .Words(i).Text
i = i + 2
End If
End If
Next
End With

End Sub

Thanks in advance

Regards,
Sudhir.





  #3   Report Post  
Posted to microsoft.public.word.formatting.longdocs
Stefan Blom[_3_] Stefan Blom[_3_] is offline
external usenet poster
 
Posts: 6,897
Default Add 0 before decimal point through VBA

Thinking about it, the character before the period is a space, so you
should be able to do it more easily as follows:

"Find what": ( )(.)([0-9])

"Replace with": 0\2\3

(Again, there is a space before the zero in "Replace with.")

Stefan Blom
Microsoft Word MVP





On 2012-06-06 13:17, Stefan Blom wrote:
A wildcard search should do the trick. There might be more efficient
ways, but here's one attempt:

"Find what": ([!0-9])(.)([0-9])

"Replace with": 0\2\3

(Note that I have entered a space before the zero in the "Replace with"
box.)

Test it on a *copy* of your document.

Stefan Blom
Microsoft Word MVP





On 2012-06-05 06:54, Sudhir_Gawade wrote:
Hi,

In my MS Word document, there are about 50 pages. I need to add "0"
where decimal value is in this format .25 or any Number. I need VBA
code.

I have tried with below, but it is time consuming is there other way of
doing same.

Sub a()

With ActiveDocument
For i = 1 To .Words.Count

If .Words(i).Text = "." Then

If IsNumeric(.Words(i).Text & .Words(i + 1).Text) And .Words(i - 1).Text
"0" Then

.Words(i).Text = "0" & .Words(i).Text
i = i + 2
End If
End If
Next
End With

End Sub

Thanks in advance

Regards,
Sudhir.






  #4   Report Post  
Sudhir_Gawade Sudhir_Gawade is offline
Junior Member
 
Posts: 3
Thumbs up

Hi Stefan,

Thanks for your reply.


Sudhir Gawade.

Quote:
Originally Posted by Stefan Blom[_3_] View Post
Thinking about it, the character before the period is a space, so you
should be able to do it more easily as follows:

"Find what": ( )(.)([0-9])

"Replace with": 0\2\3

(Again, there is a space before the zero in "Replace with.")

Stefan Blom
Microsoft Word MVP





On 2012-06-06 13:17, Stefan Blom wrote:
A wildcard search should do the trick. There might be more efficient
ways, but here's one attempt:

"Find what": ([!0-9])(.)([0-9])

"Replace with": 0\2\3

(Note that I have entered a space before the zero in the "Replace with"
box.)

Test it on a *copy* of your document.

Stefan Blom
Microsoft Word MVP





On 2012-06-05 06:54, Sudhir_Gawade wrote:
Hi,

In my MS Word document, there are about 50 pages. I need to add "0"
where decimal value is in this format .25 or any Number. I need VBA
code.

I have tried with below, but it is time consuming is there other way of
doing same.

Sub a()

With ActiveDocument
For i = 1 To .Words.Count

If .Words(i).Text = "." Then

If IsNumeric(.Words(i).Text & .Words(i + 1).Text) And .Words(i - 1).Text
"0" Then

.Words(i).Text = "0" & .Words(i).Text
i = i + 2
End If
End If
Next
End With

End Sub

Thanks in advance

Regards,
Sudhir.




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
align numbers by decimal point HAH Tables 2 May 23rd 07 09:02 PM
decimal point Terry Tables 5 January 30th 07 09:48 AM
Getting Decimal Point With Mail Merge Bethesda CPA Mailmerge 1 November 10th 06 05:40 AM
Decimal Point alignment notloiseweiss Tables 2 November 11th 05 09:43 PM
Change a decimal point (.) by coma (,) Thomas Mailmerge 4 February 17th 05 02:59 PM


All times are GMT +1. The time now is 09:46 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"