Solved

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

Posted on 2013-05-13
5
247 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 46

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 46

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 46

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
How to read BOM (Byte Order Mark) from csv file. 4 35
Tags from access to excel 3 26
macro for each dropdown 15 44
InStr Function not working properly in macro 3 19
Introduction This Article briefly covers methods of calculating the NPV and IRR variants in Excel as well as the limitations in calculating and interpreting IRR results. Paraphrasing Richard Shockley, author of my favourite finance reference tex…
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.
This Micro Tutorial will demonstrate on a Mac how to change the sort order for chart legend values and decrpyt the intimidating chart menu.

929 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