OK, not quite a eureka moment, but the following should work:
It formats numbers in the format #.## or # in the third table column (set at
iCol = 3)
to use either GBP or EUR currency separators. Calculated fields are updated
and converted to text before formatting.
I have crossposted to the vba general forum in case someone there has a
simpler solution.
Sub FormatColumnAsCurrency()
Dim cTable As Table
Dim oRng As Range
Dim sNum, sCent, sEuro, sTEuro, sMEuro As String
Dim sSep, sDec, sCurr, sSign As String
Dim iCol As Integer
Dim i As Long
Dim count As Variant
'Set column number containing the amounts
iCol = 3
sCurr = InputBox("Enter Y to format table as Euro" & vbCr & _
"Enter anything else to format as Sterling", _
"Format currency", "Y")
Set cTable = ActiveDocument.Tables(1)
For i = 1 To cTable.Rows.count
Set oRng = cTable.Cell(i, iCol).Range
On Error Resume Next
With oRng.Fields
.Update
.Unlink
End With
Next i
For i = 1 To cTable.Rows.count
Set oRng = cTable.Cell(i, iCol).Range
sNum = Replace(oRng, Chr(13) & Chr(7), "")
sNum = Replace(sNum, ",", "")
If InStr(1, sNum, ".") = False Then
sNum = sNum & ".00"
End If
If UCase(sCurr) = "Y" Then
sSep = "."
sDec = ","
sSign = "EUR "
Else
sSep = ","
sDec = "."
sSign = "GBP "
End If
sCent = sDec & Right(sNum, 2)
sEuro = Right(Int(sNum), 3)
If sNum > 999999 Then
sMEuro = Right(Int(sNum / 1000000), 3) & sSep
Else
sMEuro = ""
End If
If sNum > 999 Then
sTEuro = Right(Int(sNum / 1000), 3) & sSep
Else
sTEuro = ""
End If
sResult = Replace(oRng, sNum, sSign & sMEuro & sTEuro & sEuro & sCent)
sResult = sSign & sMEuro & sTEuro & sEuro & sCent
oRng = Replace(sResult, Chr(13), "")
Next i
End Sub
--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>