Consulting

Results 1 to 9 of 9

Thread: From Abbreviation to full form street address Column E

  1. #1

    From Abbreviation to full form street address Column E

    Hi ,hope you are doing great .
    For a active sheet i need a Dynamic range Excel Vba code.
    I want to put my abbreviations in full form.
    if My words are inside a row or column it works also there.
    Abbreaviation Full form
    Rd. Road
    St. Street
    Ln. Lane
    E East
    W West
    N North
    if you have any query related to it please message me i will help you.
    God bless you.
    Attached Images Attached Images

  2. #2
    VBAX Mentor
    Joined
    Nov 2022
    Location
    The Great Land
    Posts
    335
    Location
    Could would need to perform recursive Replace operation. Need hard-coded substitution pairs or loop through recordset.

    It would not be simple nor can it be guaranteed accurate. How would code deal with address like 222 St. John's St.?
    How to attach file: Reading and Posting Messages (vbaexpress.com), click Go Advanced below post edit window. To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,726
    Location
    This will do what you asked, but as June7 says it's not perfect

    I don't know what Dynamic range Excel Vba code. exactly means so I just used what ever cells were selected

    Option Explicit
    
    
    Sub ReplaceAbbr()
        Call pvtReplace("rd.", "Road")
        Call pvtReplace("st.", "Street")
        Call pvtReplace("ln.", "Lane")
        Call pvtReplace("E ", "East ")
        Call pvtReplace("W ", "West ")
        Call pvtReplace("N ", "North")
    End Sub
    
    
    Private Sub pvtReplace(Abbr As String, Repl As String)
        Selection.Replace What:=Abbr, Replacement:=Repl, _
            LookAt:=xlPart, SearchOrder:=xlByRows, MatchCase:=False, _
            SearchFormat:=False, ReplaceFormat:=False, FormulaVersion:=xlReplaceFormula2
    End Sub
    ---------------------------------------------------------------------------------------------------------------------

    Paul


    Remember: Tell us WHAT you want to do, not HOW you think you want to do it

    1. Use [CODE] ....[/CODE ] Tags for readability
    [CODE]PasteYourCodeHere[/CODE ] -- (or paste your code, select it, click [#] button)
    2. Upload an example
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) / Upload Files / Done
    3. Mark the thread as [Solved] when you have an answer
    Thread Tools (on the top right corner, above the first message)
    4. Read the Forum FAQ, especially the part about cross-posting in other forums
    http://www.vbaexpress.com/forum/faq...._new_faq_item3

  4. #4
    Can I attach a link youtube recorded video .from there you can easily see my instructions

  5. #5
    VBAX Mentor
    Joined
    Nov 2022
    Location
    The Great Land
    Posts
    335
    Location
    Might not be able to post clickable links until you have a certain number of posts (spam prevention).

    You can post it as non-clickable - exclude http and/or www prefix or insert spaces: w w w.
    How to attach file: Reading and Posting Messages (vbaexpress.com), click Go Advanced below post edit window. To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  6. #6
    Moderator VBAX Wizard Aussiebear's Avatar
    Joined
    Dec 2005
    Location
    Queensland
    Posts
    5,058
    Location
    Just guessing here
    Private Sub ExpandAbbreviation()
    Dim lr as Long
    Dim dRng as Range
    lr = Cells(Rows.Count,"E").End(xlUp).Row
    Set dRng = Range("E2:E" & lr)
    For each cell in dRng
       Call pvtReplace("rd.","Road")
       Call pvtReplace("st.","Street")
       Call pvtReplace("ln.", "Lane")
       Call pvtReplace("Blvd", "Boulevard")
       Call pvtReplace("E.", "East")
       Call pvtReplace("N.", "North")
       Call pvtReplace("W.", "West")
       Call pvtReplace("S.", "South")
    Next
    End Sub
    
    Private Sub pvtReplace(Abbr as String, Real as String)
    Selection.Replace What:=Abbr, Replacement := Repl, Lookout := xlPart, SearchOrder := xlByRows, _
    MatchCase := False, SearchFormat := False, ReplaceFormat := False, FormulaVersion := xlReplaceFormula2
    End Sub
    As both Paul and June7 have alluded to, this method will fail based on a number of issues. For example "NW" will not find "North West" because you haven't yet defined it. What happens if the data entry was simply "S" or "N" where the punctuation point wasn't entered? If time was on your side perhaps you could keep adding Call pvtReplace to each and every abbreviation but this could be nearly endless. It will also fail when you have abbreviations St. John for example.
    Remember To Do the Following....
    Use [Code].... [/Code] tags when posting code to the thread.
    Mark your thread as Solved if satisfied by using the Thread Tools options.
    If posting the same issue to another forum please show the link

  7. #7
    Moderator VBAX Wizard Aussiebear's Avatar
    Joined
    Dec 2005
    Location
    Queensland
    Posts
    5,058
    Location
    Quote Originally Posted by June7 View Post
    Might not be able to post clickable links until you have a certain number of posts (spam prevention).
    The administrator has a predetermined number of posts set before you can post links. Not sure of the limit but it might be as low as 10 posts
    Remember To Do the Following....
    Use [Code].... [/Code] tags when posting code to the thread.
    Mark your thread as Solved if satisfied by using the Thread Tools options.
    If posting the same issue to another forum please show the link

  8. #8
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,726
    Location
    Quote Originally Posted by KAMRAN AJ View Post
    Can I attach a link youtube recorded video .from there you can easily see my instructions
    It would be better if you attached a small sample workbook and clearly described what you were looking to do

    For example, "Dynamic Range" could have many meanings
    ---------------------------------------------------------------------------------------------------------------------

    Paul


    Remember: Tell us WHAT you want to do, not HOW you think you want to do it

    1. Use [CODE] ....[/CODE ] Tags for readability
    [CODE]PasteYourCodeHere[/CODE ] -- (or paste your code, select it, click [#] button)
    2. Upload an example
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) / Upload Files / Done
    3. Mark the thread as [Solved] when you have an answer
    Thread Tools (on the top right corner, above the first message)
    4. Read the Forum FAQ, especially the part about cross-posting in other forums
    http://www.vbaexpress.com/forum/faq...._new_faq_item3

  9. #9
    Moderator VBAX Master georgiboy's Avatar
    Joined
    Mar 2008
    Location
    Kent, England
    Posts
    1,197
    Location
    If you have Excel 365 then you could also use a formula that would look up a list for the changes - this would allow you to keep the lookup list dynamic and add/ remove items. See below and attached.
    =LET(rng,A2:A32,f,H2:H26,r,I2:I26,MAP(rng,LAMBDA(x,LET(t,TEXTSPLIT(x," ",,TRUE),TEXTJOIN(" ",TRUE,IFNA(XLOOKUP(t,f,r),t))))))
    Attached Files Attached Files
    Click here for a guide on how to add code tags
    Click here for a guide on how to mark a thread as solved
    Click here for a guide on how to upload a file with your post

    Excel 365, Version 2403, Build 17425.20146

Posting Permissions

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