+ Reply to Thread
Results 1 to 2 of 2
  1. #1
    Registered User
    Join Date
    11-27-2009
    Location
    Cedar Creek (Austin), Texas
    MS-Off Ver
    Excel 2003 & Excel 2007
    Posts
    45

    Make one line from Many

    Hi All,

    I have a word file that has a few lines per entry. I wish to convert it all to a table format.

    Here is my data I am presented with:
    AL Boligee 107.3 NEW AF 6kw/47m, 32-46-
    33/88-03-02 (Mildred
    R. Porter)
    As you can see, it's over three lines, sometimes more than 4.

    Here is the desired output I wish in a table format:
    AL Boligee 107.3 NEW AF 6kw/47m, 32-46-33/88-03-02 (Mildred R. Porter)

    I have attached one months worth of data, the highlighted piece in yellow is the deisred output and the location for the columns of the table.

    The beginning of each entry starts with a US/Candian State abbreviation.

    Any assistance will be appreciated, doing this manually is not the way to go.

    Thanks

    James Niven
    Cedar Creek, TX
    Attached Files Attached Files

  2. #2
    Forum Guru mrice's Avatar
    Join Date
    06-22-2004
    Location
    Surrey, England
    MS-Off Ver
    Excel 2007/2010
    Posts
    2,814

    Re: Make one line from Many

    You can do it this way. Copy your text into the first column of an Excel spreadsheet.

    Then run the following macro

    Code:
    Sub Reformat()
    For N = 1 To Cells(Rows.Count, 1).End(xlUp).Row
        'Check if first line of set - 2 uppercase letters followed by space and an uppercase followed by a lowercase letter
        If Len(Cells(N, 1)) >= 5 Then
            If IsUpperCase(Left(Cells(N, 1), 1)) And IsUpperCase(Mid(Cells(N, 1), 2, 1)) And Mid(Cells(N, 1), 3, 1) = " " And IsUpperCase(Mid(Cells(N, 1), 4, 1)) And IsLowerCase(Mid(Cells(N, 1), 5, 1)) Then
                FirstLine = True
            Else
                FirstLine = False
            End If
        Else
            FirstLine = False
        End If
        If FirstLine = True Then
            Cells(Rows.Count, 3).End(xlUp).Offset(1, 0) = Cells(N, 1)
        Else
            Cells(Rows.Count, 3).End(xlUp) = Cells(Rows.Count, 3).End(xlUp) & Cells(N, 1)
        End If
    Next N
    
    For N = 2 To Cells(Rows.Count, 3).End(xlUp).Row
        Cells(N, 4) = Left(Cells(N, 3), 2)
        
        'Find first number
        For M = 5 To Len(Cells(N, 3))
            If IsNumeric(Mid(Cells(N, 3), M, 1)) Then Exit For
        Next M
        
        Cells(N, 5) = Mid(Cells(N, 3), 4, M - 5) 'City
        
        For P = M To Len(Cells(N, 3))
            If IsNumeric(Mid(Cells(N, 3), M, P - M + 1)) = False Then Exit For
        Next P
    
        Cells(N, 6) = Mid(Cells(N, 3), M, P - M - 1) 'Frequency
        
        For S = P + 1 To Len(Cells(N, 3))
            If Mid(Cells(N, 3), S, 1) = " " Then Exit For
        Next S
        Cells(N, 7) = Mid(Cells(N, 3), P, S - P)
        Cells(N, 8) = Mid(Cells(N, 3), S + 1)
    Next N
    
    
    End Sub
    
    
    Function IsUpperCase(TestCharacter) As Boolean
    If Asc(TestCharacter) >= 65 And Asc(TestCharacter) <= 90 Then
        IsUpperCase = True
    Else
        IsUpperCase = False
    End If
    End Function
    
    Function IsLowerCase(TestCharacter) As Boolean
    If Asc(TestCharacter) >= 97 And Asc(TestCharacter) <= 122 Then
        IsLowerCase = True
    Else
        IsLowerCase = False
    End If
    End Function
    Open up the VBA editor by hitting ALT F11

    Insert a new module by hitting Insert - Module

    Paste the macro into the empty sheet

    Hit ALT F11 to get back to the worksheet.

    Run the macro by going to tools-macro in Excel 2003 or the view ribbon in Excel 2007.

    You can then save the output tab separated and open in Word as needed.
    Last edited by mrice; 11-28-2009 at 05:39 PM.
    Martin

    Eighty Twenty Spreadsheet Automation http://homepage.ntlworld.com/martin.rice1/ for all your Excel customisation and consulting needs.

    If my solution has saved you time and/or money, please consider donating to Cancer Research UK.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.2.0