Solved

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

Posted on 2013-05-13
5
238 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 45

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 45

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 45

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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Dealing with unintended Excel Active-X resizing quirks (VBA code simulates "self correction") David Miller (dlmille) Intro Not everyone is a fan of Active-X controls in spreadsheets (as opposed to the UserForm approach, the older Form controls …
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;…
Graphs within dashboards are meant to be dynamic, representing data from a period of time that will change each time the dashboard is updated with new data. Rather than update each graph to point to a different set within a static set of data, t…
This Micro Tutorial will demonstrate in Google Sheets how to use the HYPERLINK function to create live links inside your spreadsheet.

744 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now