Solved

separate selected contents of excel cell into 5 separate cells (columns)

Posted on 2013-05-13
5
281 Views
Last Modified: 2013-05-13
Column A contains  a number, name, address, suburb, postcode, telephone number and category.

Columns C is to contain first 3 words of the name immediately after the number from column A.
Column D is to contain the street number and name from immediately after Get Directions.
Column E is to contain the suburb from after the comma at the end of street name.
Column F is to contain the postcode following the suburb.
Column G is to contain the telephone number from immediately after the postcode
Column H is to contain all the words that follow Category:
separate-selected-contents-of-on.xlsx
0
Comment
Question by:gregfthompson
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
5 Comments
 
LVL 93

Expert Comment

by:Patrick Matthews
ID: 39161249
Columns C is to contain first 3 words of the name immediately after the number from column A.

Looking at the examples in your attached file, your first two examples violate this rule.  You have the following in C3:C4...

RE/MAX Real Estate Solutions    (4 words)
hockingstuart             (1 word)

So, what is the real requirement?
0
 
LVL 48

Expert Comment

by:Martin Liss
ID: 39161627
Even if you can further define the requirements as requested by matthewspatrick, your request is pretty much impossible because the content/format of the data (particularly the street address) isn't consistent. For example in row 7 your requirement to get the street number is messed up by "1st Floor" and in row 13 by "Suite 2".
0
 
LVL 48

Accepted Solution

by:
Martin Liss earned 500 total points
ID: 39162018
Here's some code that handles most but not all of the problems. Please note the comment at line 36.

Sub SplitData()
Dim lngLastRow As Long
Dim lngRow As Long
Dim strParts() As String
Dim intPos1 As Integer
Dim intPos2 As Integer

lngLastRow = Range("A65536").End(xlUp).Row

On Error Resume Next
For lngRow = 3 To lngLastRow
    ' NAME
    If IsNumeric(Left(Cells(lngRow, 1).Value, 1)) Then
        intPos1 = InStr(1, Cells(lngRow, 1).Value, " ")
    Else
        intPos1 = 0
    End If
    strParts = Split(Mid(Cells(lngRow, 1).Value, intPos1 + 1), " ")
    Cells(lngRow, 3).Value = strParts(0) & " " & strParts(1) & " " & strParts(2)
    ' ADDRESS
    intPos1 = InStr(1, UCase(Cells(lngRow, 1).Value), "GET DIRECTIONS ")
    If intPos1 > 0 Then
        intPos2 = InStr(intPos1, UCase(Cells(lngRow, 1).Value), ",")
        Cells(lngRow, 4).Value = Mid(Cells(lngRow, 1).Value, intPos1 + 15, intPos2 - intPos1 - 15)
    Else
        Cells(lngRow, 4).Value = ""
    End If
    
    ' SUBURB
    If intPos1 > 0 Then
        intPos1 = intPos2 + 2
        intPos2 = InStr(intPos1, Cells(lngRow, 1).Value, " ")
        Cells(lngRow, 5).Value = Mid(Cells(lngRow, 1).Value, intPos1, intPos2 - intPos1)
    Else
        Select Case True
            ' ==> Additional Cases are needed here for all possible suburbs
            Case InStr(1, Cells(lngRow, 1).Value, "Ballarat Central") > 0
                Cells(lngRow, 5).Value = "Ballarat Central"
                intPos1 = InStr(1, Cells(lngRow, 1).Value, "Ballarat Central")
            Case InStr(1, Cells(lngRow, 1).Value, "Ballarat") > 0
                Cells(lngRow, 5).Value = "Ballarat"
                intPos1 = InStr(1, Cells(lngRow, 1).Value, "Ballarat")
        End Select
    End If
    ' POSTCODE
    intPos1 = InStr(intPos1, UCase(Cells(lngRow, 1).Value), "VIC ")
    If intPos1 > 0 Then
        intPos2 = InStr(intPos1 + 4, Cells(lngRow, 1).Value, " ")
        Cells(lngRow, 6).Value = Mid(Cells(lngRow, 1).Value, intPos1 + 4, intPos2 - intPos1 - 4)
    Else
        Cells(lngRow, 6).Value = ""
        intPos1 = 1
    End If
    
    ' TELEPHONE
    intPos1 = InStr(intPos1, UCase(Cells(lngRow, 1).Value), "(")
    Cells(lngRow, 7).Value = Mid(Cells(lngRow, 1).Value, intPos1, 14)
    If Left(Cells(lngRow, 7).Value, 3) = "(0)" Then
        Cells(lngRow, 7).Value = ""
    End If
    
    ' CATEGORY
    intPos1 = InStr(intPos1, UCase(Cells(lngRow, 1).Value), "CATEGORY:")
    Cells(lngRow, 8).Value = Mid(Cells(lngRow, 1).Value, intPos1 + 10)
Next

End Sub

Open in new window

0
 

Author Closing Comment

by:gregfthompson
ID: 39163137
Great Job! Thank you.
0
 
LVL 48

Expert Comment

by:Martin Liss
ID: 39163140
You're welcome and I'm glad I was able to help.

Marty - MVP 2009 to 2013
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A little background as to how I came to I design this code: Around 5 years ago I designed an add-in that formatted Excel files to a corporate standard, applying different cell colours and font type depending on whether the cells contained inputs,…
This article describes a serious pitfall that can happen when deleting shapes using VBA.
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

627 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question