+ Reply to Thread
Results 1 to 22 of 22

Excel formula to convert sentence in number

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    09-13-2013
    Location
    Saudi Arabia
    MS-Off Ver
    2010, 2013
    Posts
    192

    Question Excel formula to convert sentence in number

    Hai,

    I have came across to some interesting question by a management. The question is can we add letter as numbers. Meaning each letter assigned a number and it should add or sum the numbers.

    I have letter A-Z in column A and number assigned to each letter in Column B.

    So if user type any word or words then it should sum the numbers and give me the total.

    For Example:

    Example 1
    C = E
    E = 5
    L = 12
    X = 24
    
    So the word is Excel which is equal to 5+24+3+5+12 = total 39
    Example 2
    W = 23
    o = 15
    r = 18
    l = 12
    d = 4
    
    So the word is Excel which is equal to 23+15+18+12+4 = total 72
    Appreciate if some1 can help me to get formula or VBA function as my data is huge with 700K - 900K rows

  2. #2
    Forum Expert Olly's Avatar
    Join Date
    09-10-2013
    Location
    Darlington, UK
    MS-Off Ver
    Excel 2016, 2019, 365
    Posts
    6,284

    Re: Excel formula to convert sentence in number

    A small UDF does the trick:
    Function SumLetters(ByVal MyString As String) As Long
        Dim l As Long, i As Integer
        For l = 1 To Len(MyString)
            i = Asc(UCase(Mid(MyString, l, 1)))
            If i >= 65 And i <= 90 Then SumLetters = SumLetters + i - 64
        Next l
    End Function
    Use as:
    Formula: copy to clipboard
    =SumLetters(A1)
    let Source = #table({"Question","Thread", "User"},{{"Answered","Mark Solved", "Add Reputation"}}) in Source

    If I give you Power Query (Get & Transform Data) code, and you don't know what to do with it, then CLICK HERE

    Walking the tightrope between genius and eejit...

  3. #3
    Forum Contributor
    Join Date
    09-13-2013
    Location
    Saudi Arabia
    MS-Off Ver
    2010, 2013
    Posts
    192

    Re: Excel formula to convert sentence in number

    Thanks Olly for your response.

    I forget to mentioned that numeric values are not fix to as same as mentioned above. Above mentioned number is the example only.

    A value can be 100 or the user input in the column B

  4. #4
    Forum Expert Olly's Avatar
    Join Date
    09-10-2013
    Location
    Darlington, UK
    MS-Off Ver
    Excel 2016, 2019, 365
    Posts
    6,284

    Re: Excel formula to convert sentence in number

    Quote Originally Posted by Abdur_rahman View Post
    I forget to mentioned that numeric values are not fix to as same as mentioned above. Above mentioned number is the example only.

    A value can be 100 or the user input in the column B
    Sorry, I don't understand this at all.

  5. #5
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS 365 Family 64-bit 2502
    Posts
    26,995

    Re: Excel formula to convert sentence in number

    I think he means that in his example, each letter is associated with its position in the English alphabet, 1-26. But in the real data, there is a translation table so that each letter in column A corresponds to a number given in column B. So you cannot use function Asc to translate the letter to a number, it has to be a lookup in columns A:B.

    (I don't know what the bit about 100 means.)
    Jeff
    | | |·| |·| |·| |·| | |:| | |·| |·|
    Read the rules
    Use code tags to [code]enclose your code![/code]

  6. #6
    Forum Contributor
    Join Date
    09-13-2013
    Location
    Saudi Arabia
    MS-Off Ver
    2010, 2013
    Posts
    192

    Re: Excel formula to convert sentence in number

    Let me explain.

    I have letter in column A and numbers in column B.

    The function or formula look for that letter in Column A and see what is the number next to it in Column B.

    It need to check entire string in Column C which is a big list and sum the total.

    I hope I have explained correctly to make you understand. If not please give me some time to prepare some samples and attached a worksheet.

  7. #7
    Forum Expert Olly's Avatar
    Join Date
    09-10-2013
    Location
    Darlington, UK
    MS-Off Ver
    Excel 2016, 2019, 365
    Posts
    6,284

    Re: Excel formula to convert sentence in number

    Ah, I see.

    Go on, pop up a sample workbook, to make sure I'm not making any rash assumptions!

  8. #8
    Forum Contributor
    Join Date
    09-13-2013
    Location
    Saudi Arabia
    MS-Off Ver
    2010, 2013
    Posts
    192

    Re: Excel formula to convert sentence in number

    Thanks 6StringJazzer for converting my hard words into simple explanation.

    This is what I am trying to say.

    How ever I am attaching a sample for your reference.

  9. #9
    Valued Forum Contributor dmcgov's Avatar
    Join Date
    11-11-2015
    Location
    Florida, USA
    MS-Off Ver
    Office 365 Business
    Posts
    1,518

    Re: Excel formula to convert sentence in number

    this should work for you:

    Sub get_alpa_num()
        Dim wb     As Workbook
        Set wb = ThisWorkbook
        Dim ws     As Worksheet
        Set ws = Sheets("Sheet4")
        Dim rng    As Range
        Set rng = Range("D2")
        Dim x      As Long
        Dim a      As Long
    
        For x = 1 To Len(rng)
            sFind = Mid(rng.Value, x, 1)
            Set RNG2 = Sheets("Sheet4").Range("A1:A26")
            Set cl = RNG2.Find(sFind, LookIn:=xlValues)
            If Not cl Is Nothing Then
                If cl = " " Then
                'do nothing
                Else
                a = a + cl.Offset(0, 1).Value
                End If
            End If
        Next x
        Debug.Print a
    End Sub
    Last edited by dmcgov; 06-26-2019 at 11:51 AM.

  10. #10
    Forum Contributor
    Join Date
    09-13-2013
    Location
    Saudi Arabia
    MS-Off Ver
    2010, 2013
    Posts
    192

    Re: Excel formula to convert sentence in number

    Thanks dmcgov for your script but it is not working also I have huge range of sentences not only 2 cell. The above is the example how is the input.

  11. #11
    Valued Forum Contributor dmcgov's Avatar
    Join Date
    11-11-2015
    Location
    Florida, USA
    MS-Off Ver
    Office 365 Business
    Posts
    1,518

    Re: Excel formula to convert sentence in number

    what line does it fail on (choose debug) and what is the error. it is working fine on my side

  12. #12
    Forum Guru
    Join Date
    09-10-2017
    Location
    Chippenham, England
    MS-Off Ver
    365
    Posts
    15,789

    Re: Excel formula to convert sentence in number

    Another option
    Function SumString(St As String) As Double
       Dim cl As Range
       Dim i As Long
       
       With CreateObject("scripting.dictionary")
          For Each cl In Range("A1:B26")
             .Item(UCase(cl.Value)) = cl.Offset(, 1).Value
          Next cl
          For i = 1 To Len(St)
             SumString = SumString + .Item(UCase(Mid(St, i, 1)))
          Next i
       End With
    End Function

  13. #13
    Forum Contributor
    Join Date
    09-13-2013
    Location
    Saudi Arabia
    MS-Off Ver
    2010, 2013
    Posts
    192

    Re: Excel formula to convert sentence in number

    Thanks Fluff13. It is working for me if the letter are English. What about I it is not English.

    Meaning any other language. It will not work.

    What I am trying to tell you is any string in column A (Any Language) should work because it is assuming as a string not a language right.

  14. #14
    Forum Guru
    Join Date
    09-10-2017
    Location
    Chippenham, England
    MS-Off Ver
    365
    Posts
    15,789

    Re: Excel formula to convert sentence in number

    As long as you have the letters/symbols in col A then it should work.

  15. #15
    Forum Contributor
    Join Date
    09-13-2013
    Location
    Saudi Arabia
    MS-Off Ver
    2010, 2013
    Posts
    192

    Re: Excel formula to convert sentence in number

    I mean to say if I put letters Arabic or hindi or Urdu it should work right but it is not working.

  16. #16
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689

    Re: Excel formula to convert sentence in number

    The trick to getting questions answered on a forum is to ask the question you want answered, and to provide an example that illustrates.
    Entia non sunt multiplicanda sine necessitate

  17. #17
    Forum Guru
    Join Date
    09-10-2017
    Location
    Chippenham, England
    MS-Off Ver
    365
    Posts
    15,789

    Re: Excel formula to convert sentence in number

    In that case, please supply a sample workbook with representative data.

  18. #18
    Forum Contributor
    Join Date
    09-13-2013
    Location
    Saudi Arabia
    MS-Off Ver
    2010, 2013
    Posts
    192

    Re: Excel formula to convert sentence in number

    Dear Fluff13.

    Please find the attachment for 2 more languages (Arabic & Urdu) sample workbook s requested.

  19. #19
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Exclamation

    Hi !

    Quote Originally Posted by Abdur_rahman View Post
    Please find the attachment for 2 more languages (Arabic & Urdu)
    As I already have a working code for English & Urdu, I guess, no in fact I'm sure your Arabic sample value is wrong !

    So check and revert as I won't post any code until we agree on a correct Arabic result …

    Edit : the issue comes from A12 cell is equal to cell A15 ‼
    Last edited by Marc L; 06-26-2019 at 11:12 PM.

  20. #20
    Forum Guru
    Join Date
    09-10-2017
    Location
    Chippenham, England
    MS-Off Ver
    365
    Posts
    15,789

    Re: Excel formula to convert sentence in number

    Ok, try this
    Function SumString(St As String) As Double
       Dim cl As Range
       Dim i As Long
       
       With CreateObject("scripting.dictionary")
          For Each cl In Range("A1:A29")
             .Item(UCase(cl.Value)) = cl.Offset(, 1).Value
          Next cl
          For i = 1 To Len(St)
             SumString = SumString + .Item(UCase(Mid(St, i, 1)))
          Next i
       End With
    End Function
    But the value in A3 has an extra space which you need to remove

  21. #21
    Forum Contributor
    Join Date
    09-13-2013
    Location
    Saudi Arabia
    MS-Off Ver
    2010, 2013
    Posts
    192

    Re: Excel formula to convert sentence in number

    Hai Fluff13,

    Thanks for your valuable help it is working for me. I really appreciate your effort on this request. Thanks once again.

  22. #22
    Forum Guru
    Join Date
    09-10-2017
    Location
    Chippenham, England
    MS-Off Ver
    365
    Posts
    15,789

    Re: Excel formula to convert sentence in number

    You're welcome & thanks for the feedback

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] cut number from some sentence
    By kimudao in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 04-23-2019, 08:39 AM
  2. Cross reference letter case: Beginning of sentence and middle of sentence
    By caswell1000 in forum Word Formatting & General
    Replies: 4
    Last Post: 02-07-2019, 05:25 PM
  3. [SOLVED] Extract a number from a sentence to use in formula?
    By ocannon1 in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 08-22-2017, 07:40 AM
  4. Convert specific number into specific sentence
    By sarangapani in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 12-26-2013, 03:57 PM
  5. CONVERT SENTENCE TO COLUMN
    By JonnieP in forum Excel General
    Replies: 1
    Last Post: 08-07-2006, 05:45 AM
  6. Excel should have a formula to convert number into words
    By Nitish Rawat in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 12-21-2005, 03:00 PM
  7. Replies: 10
    Last Post: 10-07-2005, 03:05 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1