+ Reply to Thread
Results 1 to 15 of 15

Changing prices to letters

Hybrid View

  1. #1
    Registered User
    Join Date
    02-09-2013
    Location
    Mytown, USA
    MS-Off Ver
    Excel 2013
    Posts
    8

    Changing prices to letters

    My boss wants to convert our price column to a letter code. as in $4.50 would be DEI
    using this template:
    S I M P L Y W O R K
    1 2 3 4 5 6 7 8 9 0

    where each number becomes a number in the words simply work.

    Is there a way to create a formula or a macro the when the price is typed in a cell that it changes to the alphs code?

    Thanks
    Dan

  2. #2
    Valued Forum Contributor
    Join Date
    03-20-2011
    Location
    UK
    MS-Off Ver
    Excel 2007/10/16
    Posts
    840

    Re: Changing prices to letters

    Well to the forum

    Will this help =LOOKUP(B2, {1,5,10,15,20,25,30,35,40}, {"AA","AC","BA","BD","CA","CC","DA","DD","EA",0})
    Column A > put in $ then copy down
    Column B2 > type in say 5
    Column C2 > =LOOKUP(B2, {1,5,10,15,20,25,30,35,40}, {"AA","AC","BA","BD","CA","CC","DA","DD","EA",0}) You can change number and letter> Once done then copy down where you want to stop.
    Result > $5 would be AC

    Good Luck!
    To help you by my post? it would be nice to click on to say "Thank you".
    If you are happy with a solution to your problem?
    Click Thread Tools above your first post,
    select "Mark your thread as Solved".

  3. #3
    Registered User
    Join Date
    02-09-2013
    Location
    Mytown, USA
    MS-Off Ver
    Excel 2013
    Posts
    8

    Re: Changing prices to letters

    Actually column E will have the prices, and any price entered will need to be changed to te corresponding letter.

  4. #4
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,681

    Re: Changing prices to letters

    Quote Originally Posted by vcsindy View Post
    $4.50 would be DEI
    using this template:
    S I M P L Y W O R K
    1 2 3 4 5 6 7 8 9 0
    Can you explain why 450 would be "DEI"?
    Isn't it "PLK"?

  5. #5
    Registered User
    Join Date
    02-09-2013
    Location
    Mytown, USA
    MS-Off Ver
    Excel 2013
    Posts
    8

    Re: Changing prices to letters

    Sorry You're right...PLK. How would I isert this formula

  6. #6
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,681

    Re: Changing prices to letters

    This will covert only numbers to the correspoding letters, ignoring no numeric characters.
    i.e.
    12xyz45 becomes "IMLY"

    Change any cell(s) in Col.E

    To a WorkSheet module in question.
    Option Explicit
    
    Private Sub Worksheet_Change(ByVal Target As Range)
        Dim r As Range, txt As String, x, i As Long
        If Not Intersect(Target, Columns("e")) Is Nothing Then
            Application.EnableEvents = False
            With CreateObject("VBScript.RegExp")
                .Global = True
                .Pattern = "[^\d]+"
                For Each r In Intersect(Target, Columns("e"))
                    x = Split(StrConv(.Replace(r.Text, ""), vbUnicode), Chr(0))
                    For i = 0 To UBound(x) - 1
                        x(i) = Mid$("SIMPLYWORK", x(i) + 1, 1)
                    Next
                    r.Value = Join$(x, "")
                Next
            End With
            Application.EnableEvents = True
        End If
    End Sub

  7. #7
    Registered User
    Join Date
    02-09-2013
    Location
    Mytown, USA
    MS-Off Ver
    Excel 2013
    Posts
    8

    Re: Changing prices to letters

    tHANK yOU SO MUCH....hOW DO i USE IT? dO i PASTE IT TO THE CELL?

  8. #8
    Registered User
    Join Date
    02-09-2013
    Location
    Mytown, USA
    MS-Off Ver
    Excel 2013
    Posts
    8

    Re: Changing prices to letters

    Is there anyway the 0 before the decimal can associate with the K so 450.00 will be LYK?

  9. #9
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,681

    Re: Changing prices to letters

    It is not a function used in cell.

    Try change any cell in Sheet1 Col.E in attached, you will see how it works.
    Attached Files Attached Files

  10. #10
    Registered User
    Join Date
    02-09-2013
    Location
    Mytown, USA
    MS-Off Ver
    Excel 2013
    Posts
    8

    Re: Changing prices to letters

    Thank you thank you thank you!!! You are awesome

  11. #11
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,681

    Re: Changing prices to letters

    OOps

    1) Right click on the Sheet1 sheet tab
    2) select [View Code]

    Then you will see the codes in the right pane.

    Replace following one line
                        x(i) = Mid$("SIMPLYWORK", x(i) + 1, 1)
    with following 2 lines
                        If x(i) = 0 Then x(i) = 10
                        x(i) = Mid$("SIMPLYWORK", x(i), 1)

  12. #12
    Registered User
    Join Date
    02-09-2013
    Location
    Mytown, USA
    MS-Off Ver
    Excel 2013
    Posts
    8

    Re: Changing prices to letters

    One last question...can the script add the decimal and the code extends to the cents. such as $450.12 = plk.si
    Last edited by vcsindy; 02-10-2013 at 02:14 PM.

  13. #13
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,681

    Re: Changing prices to letters

    Replace the code with the following
    Private Sub Worksheet_Change(ByVal Target As Range)
        Dim r As Range, txt As String, x, i As Long, flg As Boolean, dg As Single
        Const myCode = "SIMPLYWORK"
        If Not Intersect(Target, Columns("e")) Is Nothing Then
            Application.EnableEvents = False
            For Each r In Intersect(Target, Columns("e"))
                If Len(r.Value) Then
                    x = Split(StrConv(r.Text, vbUnicode), Chr(0))
                    For i = 0 To UBound(x) - 1
                        Select Case True
                            Case x(i) Like "[1-9]"
                                x(i) = Mid$(myCode, x(i), 1)
                                If flg Then x(i) = LCase$(x(i)): dg = dg + 1
                                If dg = 2 Then ReDim Preserve x(i): Exit For
                            Case x(i) = 0
                                x(i) = Mid$(myCode, 10, 1)
                                If flg Then x(i) = LCase$(x(i)): dg = dg + 1
                                If dg = 2 Then ReDim Preserve x(i): Exit For
                            Case x(i) = "."
                                If flg Then
                                    If dg = 2 Then
                                        ReDim Preserve x(i - 1)
                                        Exit For
                                    Else
                                        x(i) = ""
                                    End If
                                End If
                                flg = True
                            Case Else: x(i) = ""
                        End Select
                    Next
                    r.Value = Join$(x, "") & IIf(Not flg, ".", "") _
                    & String(2 - dg, Right$(LCase$(myCode), 1))
                    flg = False: dg = 0
                End If
            Next
        End If
        Application.EnableEvents = True
    End Sub

  14. #14
    Forum Guru Winon's Avatar
    Join Date
    02-20-2007
    Location
    East Rand, R.S.A.
    MS-Off Ver
    2010
    Posts
    6,113

    Re: Changing prices to letters

    @ jindon,

    Awesome!!!

  15. #15
    Registered User
    Join Date
    02-23-2022
    Location
    Langley
    MS-Off Ver
    365
    Posts
    1

    Re: Changing prices to letters

    Is there a way to convert the number from the left column to the aphabets. Ex cell B1 is 1, it automatically produces the result S in cell C1. (using SIMPLYWORK as the example)

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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