I need to format certain columns with 4+ digits to a comma format in a number of tables. The code works for the first item in a table but then exits the loop. What am I missing?
[vba]Option Explicit
Sub TableGen()
Dim i As Long
Dim MyTable As Table
With ActiveDocument
For i = 1 To .Tables.Count
Set MyTable = .Tables(i)
Call CommaNumbering(MyTable, 4) 'Format column 4
Next
End With
End Sub
Sub CommaNumbering(MyTable As Table, i As Long)
'Method by Graham Mayor - Word MVP
Dim sText As String
Dim Rng As Range
Dim Fnd As Range
Set Rng = ActiveDocument.Range(Start:=MyTable.Cell(1, i).Range.Start, _
End:=MyTable.Cell(MyTable.Rows.Count, i).Range.End)
With Rng
With .Find
.ClearFormatting
.Replacement.ClearFormatting
Do While .Execute(findText:="[0-9]{4,}", _
MatchWildcards:=True, Wrap:=wdFindStop, _
Forward:=True) = True
Set Fnd = .Parent
Fnd.Text = Format(Fnd.Text, "###,###,##0")
Loop
End With
End With
End Sub
[/vba]