+ Reply to Thread
Results 1 to 2 of 2

Looking for appropriate function to extract words in excel cell

Hybrid View

JayshreeJK Looking for appropriate... 12-07-2012, 05:43 AM
TMS Re: Looking for appropriate... 12-07-2012, 04:39 PM
  1. #1
    Registered User
    Join Date
    12-07-2012
    Location
    Mauritius
    MS-Off Ver
    Excel 2003
    Posts
    1

    Looking for appropriate function to extract words in excel cell

    HI

    I am a list of addresses where I have to extract the locality only.Locality in Upper Case

    For e.g

    1. 12 Mahatma Gandhi st TRIOLET
    2. Royal Road MON GOUT
    3. ROCHE BOIS 12 Nicolay Road

    Wish someone can help me find the result.

    Thanks & Kind Regards

  2. #2
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    48,100

    Re: Looking for appropriate function to extract words in excel cell

    In the absence of any other response, I can offer a User Defined Function (UDF)

    Option Explicit
    
    Function GetUC(ByVal rRng As Range) As String
    'example call: =getuc(A2)
    Dim i As Long
    Dim soutput As String
    Dim wdArr
    ' separate the "words" in the cell
    wdArr = Split(rRng, " ")
    ' loop through each of the words in the array
    For i = LBound(wdArr) To UBound(wdArr)
        ' check if the array element is ALL upper case
        ' and the array element is not numeric
        If wdArr(i) = UCase(wdArr(i)) _
        And Not IsNumeric(wdArr(i)) _
        Then
            ' build an ouput string (uppercase words)
            soutput = soutput & wdArr(i) & " "
        End If
    Next 'i
    ' remove the trailinng space and return the value
    On Error Resume Next
    GetUC = Left(soutput, Len(soutput) - 1)
    ' cater for error condition, eg, no upper case values
    If Err.Number <> 0 Then GetUC = ""
    On Error GoTo 0
    
    End Function
    
    Sub Test_GetUC()
    MsgBox GetUC(Range("A2"))
    End Sub

    Open the VBE by pressing Alt-F11.
    Insert a new (Standard) Module.
    Copy and Paste the code above into the new module.

    In the spreadsheet, call the function using: =GetUC( ... cell address ...), for example, =GetUC(A2)


    Regards, TMS
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


+ 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