Solved

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

Posted on 2013-05-13
5
268 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
  • 3
5 Comments
 
LVL 92

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 47

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 47

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 47

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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

This tutorial explains how to create a series of drop-down lists that are dependent upon prior selections to guide (“force”) the user to make the correct selection and reduce data errors within Microsoft Excel. Excel 2010 was used for this tutorial;…
Workbook link problems after copying tabs to a new workbook? David Miller (dlmille) Intro Have you either copied sheets to a new workbook, and after having saved and opened that workbook, you find that there are links back to the original sou…
This Micro Tutorial demonstrates how to create Excel charts: column, area, line, bar, and scatter charts. Formatting tips are provided as well.
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…

685 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