View Single Post
 
Old 08-20-2019, 04:00 PM
gmaxey gmaxey is offline Windows 10 Office 2016
Expert
 
Join Date: May 2010
Location: Brasstown, NC
Posts: 1,429
gmaxey is a jewel in the roughgmaxey is a jewel in the roughgmaxey is a jewel in the roughgmaxey is a jewel in the rough
Default

Just for the stake of expanding what seems to work. This version auto processes $ and % plus a few others:

Code:
Sub Macro1()
Dim oTbl As Table
Dim oRng As Range
Dim strText As String
Dim lngCol As Long, lngRow As Long, lngIndex As Long
Dim varVal
Dim varSyms
  'Auto processes Dollar sign, percent sign, euro, pound sterling, and yen
  strText = "$:%:" & ChrW(8364) & ":" & ChrW(163) & ":" & ChrW(165) 'InputBox("Enter the symbols separated with colon, eg. $:%", "SYMBOLS", "$:%")
  Application.ScreenUpdating = False
  varSyms = Split(strText, ":")
  For Each oTbl In ActiveDocument.Tables
    For lngCol = 1 To oTbl.Columns.Count - 1 Step 2
      For lngRow = 1 To oTbl.Rows.Count
        Set oRng = oTbl.Cell(lngRow, lngCol).Range
        oRng.End = oRng.End - 1
        For lngIndex = 0 To UBound(varSyms)
          varVal = Split(oRng.Text, varSyms(lngIndex))
          If UBound(varVal) = 1 Then
            Select Case True
              Case Trim(varVal(0)) <> vbNullString And Trim(varVal(1)) <> vbNullString
                'Where the symbol splits two numerical values.
                oRng.Text = Trim(varVal(0)) & "." & Trim(varVal(1))
              Case Trim(varVal(0)) <> vbNullString
                'Where the symbol follows the numerical value.
                oRng.Text = Trim(varVal(0))
              Case Else
                'Where the symbol precedes the numerical value.
                oRng.Text = Trim(varVal(1))
            End Select
            oRng.Cells(1).Next.Range.Text = varSyms(lngIndex)
          End If
        Next lngIndex
      Next lngRow
      DoEvents
    Next lngCol
  Next oTbl
  Application.ScreenUpdating = True
  MsgBox "Tables processed"
lbl_Exit:
  Set oTbl = Nothing
  Set oRng = Nothing
  Exit Sub
End Sub
__________________
Greg Maxey
Please visit my web site at http://www.gregmaxey.com/
Reply With Quote