Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #2  
Old 07-05-2014, 12:54 AM
macropod's Avatar
macropod macropod is offline Convert alphabets to numeric values Windows 7 32bit Convert alphabets to numeric values Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 22,512
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

You could use a macro like:
Code:
Sub NumberStringToNumeric()
Application.ScreenUpdating = False
Dim Rng As Range, StrTmp As String, lNumber As Long, i As Long
Dim StrNums As String, StrDigits As String, StrMagTxt As String, StrMagNum As String
StrNums = "zero,one,two,three,four,five,six,seven,eight,nine,ten," & _
  "eleven,twelve,thirteen,fourteen,fifteen,sixteen,seventeen,eighteen,nineteen," & _
  "twenty,thirty,forty,fifty,sixty,seventy,eighty,ninety"
StrDigits = "0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,30,40,50,60,70,80,90"
StrMagTxt = "[Bb]illion,[Hh]undred [Mm]illion,[Mm]illion,[Hh]undred [Tt]housand,[Tt]housand,[Hh]undred"
StrMagNum = "000000000|,00000000|,000000|,00000|,000|,00|"
With ActiveDocument.Range
  With .Find
    .ClearFormatting
    .Replacement.ClearFormatting
    .Forward = True
    .Wrap = wdFindContinue
    .Format = False
    .MatchCase = False
    .MatchWholeWord = True
    .MatchWildcards = False
    For i = 0 To UBound(Split(StrNums, ","))
      .Text = Split(StrNums, ",")(i)
      .Replacement.Text = Split(StrDigits, ",")(i)
      .Execute Replace:=wdReplaceAll
    Next
    .MatchWildcards = True
    .Text = "0[ \-]([0-9])"
    .Replacement.Text = "\1"
    .Execute Replace:=wdReplaceAll
    For i = 0 To UBound(Split(StrMagTxt, ","))
      .Text = Split(StrMagTxt, ",")(i)
      .Replacement.Text = Split(StrMagNum, ",")(i)
      .Execute Replace:=wdReplaceAll
    Next
    .Wrap = wdFindStop
    .Text = "[0-9 |,]{1,}"
    .Execute
  End With
  Do While .Find.Found
    lNumber = 0
    Set Rng = .Duplicate
    With Rng
      While Not IsNumeric(.Characters.Last)
        .End = .End - 1
      Wend
      StrTmp = Replace(Replace(.Text, "| ", "|"), ", ", "")
      For i = 0 To UBound(Split(StrTmp, "|")) - 1
        If UBound(Split(Split(StrTmp, "|")(i + 1), " ")) > 0 Then
          If Len(Split(Split(StrTmp, "|")(i), " ")(1)) > Len(Split(Split(StrTmp, "|")(i + 1), " ")(1)) Then
            lNumber = lNumber + CLng(Replace(Split(StrTmp, "|")(i), " ", ""))
          Else
            lNumber = lNumber + CLng(Replace(Split(StrTmp, "|")(i), " ", "") & Split(Split(StrTmp, "|")(i + 1), " ")(1))
          End If
        Else
          lNumber = lNumber + CLng(Replace(Split(StrTmp, "|")(i), " ", ""))
        End If
      Next
      lNumber = lNumber + CLng(Replace(Split(StrTmp, "|")(UBound(Split(StrTmp, "|"))), " ", ""))
    End With
    .Text = Format(lNumber, "#,##0")
    .Collapse wdCollapseEnd
    .Find.Execute
  Loop
End With
Application.ScreenUpdating = True
End Sub
Note: The code assumes your number strings don't include the 'and' that is common in UK English, for example (e.g. one hundred and one). It's also not really designed for handling currencies or decimals, though it should handle the numeric aspects of those OK too.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
 

Tags
alphabet to numeric, convert, formula

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Convert alphabets to numeric values Sorting Alphanumeric & Numeric values slovenc0417 Excel 2 06-07-2013 07:58 PM
Convert alphabets to numeric values Handle Text / Numeric values in SSRS while Export To Excel achuki Excel 5 02-07-2012 02:14 PM
Convert alphabets to numeric values Convert numeric value into words KIM SOLIS Excel 5 09-12-2011 10:53 PM
Convert alphabets to numeric values [How To] Generate Alpha Numeric Values in Excel 2010 stnicholas81 Excel 1 07-25-2011 01:31 AM
Convert alphabets to numeric values Running alphabets at left margins and pinpoint cites at right margin ghumdinger Word 3 05-05-2011 02:01 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 02:08 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft