PDA

View Full Version : Is there any option in word like "Excel - Find - Match entire cell contents"



AlexandarR
11-16-2015, 07:18 AM
Hi Guys,

I have a big table which have full of decimal values like 1.23, 2.34, etc. But, in some instances there is values like .12, .34, etc. (naked decimals), which are to be changed as 0.12, 0.34, etc. Also, table data has formatted with style "tab-body". Is it possible to find only naked decimal values (.12, .34, etc.) in table cells with style "tab-body".

I am using the following code, but not working. Is there any option in word like "Excel - Find - Match entire cell contents"?



Sub a_BodyText11B()
Dim strFind() As String
Dim oRng As Range
Dim bFound As Boolean
Dim i As Long
strFind = Split("[!0-9].([0-9]@>)|\(.([0-9]@>)", "|")
For i = LBound(strFind) To UBound(strFind)
Set oRng = ActiveDocument.Range
With oRng.Find
Do While .Execute(strFind(i), MatchWildcards:=True, MatchWholeWord:=True)
If oRng.Style = "tab-head" Or oRng.Style = "tab-body" Then
oRng.HighlightColorIndex = wdTurquoise
'oRng.Font.Color = wdColorPink
oRng.Comments.Add oRng, "CE: Naked decimals are not allowed. Ex: .03, add a zero to the left of the decimal: 0.03."
bFound = True
End If
oRng.Collapse wdCollapseEnd
Loop
End With
Next i
lbl_Exit:
Exit Sub
End Sub


Please help :help!!!

Thanks,
Alex

gmaxey
11-16-2015, 05:44 PM
No.

Maybe something like this:


Sub a_BodyText11B()
Dim oRng As Range
Set oRng = ActiveDocument.Range
With oRng.Find
.Text = "."
.Style = "tab-body"
While .Execute
If IsNumeric(oRng.Characters.Last.Next) And Not IsNumeric(oRng.Characters.First.Previous) Then
oRng.Comments.Add oRng, "CE: Naked decimals are not allowed. Ex: .03, add a zero to the left of the decimal: 0.03."
oRng.Collapse wdCollapseEnd
End If
Wend
End With
lbl_Exit:
Exit Sub
End Sub

AlexandarR
11-21-2015, 06:22 AM
Thank you very much!! It works fine.:clap:

gmaxey
11-21-2015, 02:42 PM
You're welcome.