Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2013-05-13
5
Medium Priority
?
284 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 49

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 49

Accepted Solution

by:
Martin Liss earned 2000 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 49

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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

How to get Spreadsheet Compare 2016 working with the 64 bit version of Office 2016
Access developers frequently have requirements to interact with Excel (import from or output to) in their applications.  You might be able to accomplish this with the TransferSpreadsheet and OutputTo methods, but in this series of articles I will di…
The viewer will learn how to create a normally distributed random variable in Excel, use a normal distribution to simulate the return on an investment over a period of years, Create a Monte Carlo simulation using a normal random variable, and calcul…
This Micro Tutorial will demonstrate on a Mac how to change the sort order for chart legend values and decrpyt the intimidating chart menu.

670 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