+ Reply to Thread
Results 1 to 3 of 3

Thread: Extract data from cells

  1. #1
    Registered User
    Join Date
    03-19-2010
    Location
    VT, USA
    MS-Off Ver
    Excel 2010
    Posts
    28

    Extract data from cells

    I have a more complex scenario for extracting specific data from cells. I have a spreadsheet with over 30,000 lines. Each line has a cell similar to the attached spreadsheet A column. However for each entry in my spreadsheet the number of line items in the cell may vary, as shown in the sample doc.

    I'm looking for a formula that will allow me to extract the text I've highlighted in red and present in a comma separate list in the B column.

    Possible?
    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
    3,004

    Re: Extract data from cells

    Try this user defined function.

    Function GetList(InputCell As Range) As String
    NewLine = True
    Capture = False
    CaptureString = ""
    For N = 1 To Len(InputCell.Value)
        If Mid(InputCell.Value, N, 1) = "=" Then
            Capture = True
        End If
        
        If Mid(InputCell.Value, N, 1) = Chr$(10) Then
            Capture = True
            NewLine = True
        End If
        
        If Capture = True And NewLine = True Then
            If Mid(InputCell.Value, N, 1) = "," Then
                Capture = False
                CaptureString = CaptureString & ", "
                NewLine = False
    
            End If
        End If
        
        If Capture = True And Mid(InputCell.Value, N, 1) <> "=" And NewLine = True Then
            CaptureString = CaptureString & Mid(InputCell.Value, N, 1)
        End If
    
    Next N
    
    If Len(CaptureString) >= 2 Then CaptureString = Left(CaptureString, Len(CaptureString) - 2)
    GetList = CaptureString
    
    End Function
    Paste this into a new module in the VBA editor (Alt F11)

    Then use like =GetList(A2)
    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.

  3. #3
    Registered User
    Join Date
    03-19-2010
    Location
    VT, USA
    MS-Off Ver
    Excel 2010
    Posts
    28

    SOLVED Re: Extract data from cells

    Perfect - amazing - and just saved me a MASSIVE amount of work. Thank you so much!!

+ Reply to Thread

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