Consulting

Results 1 to 4 of 4

Thread: How to extract a specific data in a column and parse it in another column with VBA

  1. #1

    Question How to extract a specific data in a column and parse it in another column with VBA

    Hello everyone ,

    I have some trouble to solve this issue

    So my goal is to extract a specific information in a column and parse it to another column like this

    VBA.JPG



    Can you help me for the vba code

    Column B= data

    Column D = the result i wanna get

    The workbook is attached

    Kind regards,
    Attached Files Attached Files

  2. #2
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,711
    Location
    I think a User Defined Function (UDF) is the way to go

    Someone probably has a long complicated worksheet formula that does the same, but I prefer a UDF

    ASSUMING that the Part number or whatever you want to extract has the same structure


    Capture.JPG

    Option Explicit
    
    
    Function ExtractPart(s As String) As String
        Dim v As Variant
        Dim i As Long
        
        ExtractPart = Empty
        
        v = Split(s, " ")
        
        For i = LBound(v) To UBound(v)
            v(i) = UCase(Trim(v(i)))
            If Len(v(i)) = 11 Then
                If v(i) Like "[A-Z][A-Z]#########" Then
                    ExtractPart = v(i)
                    Exit Function
                End If
            End If
        Next i
    End Function
    Attached Files Attached Files
    ---------------------------------------------------------------------------------------------------------------------

    Paul


    Remember: Tell us WHAT you want to do, not HOW you think you want to do it

    1. Use [CODE] ....[/CODE ] Tags for readability
    [CODE]PasteYourCodeHere[/CODE ] -- (or paste your code, select it, click [#] button)
    2. Upload an example
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) / Upload Files / Done
    3. Mark the thread as [Solved] when you have an answer
    Thread Tools (on the top right corner, above the first message)
    4. Read the Forum FAQ, especially the part about cross-posting in other forums
    http://www.vbaexpress.com/forum/faq...._new_faq_item3

  3. #3
    Thank you

    It's working

    Kind regards

  4. #4
    Knowledge Base Approver VBAX Wizard
    Joined
    Apr 2012
    Posts
    5,635
    Or

    Function F_snb(c00)
        For Each F_snb In Split(c00)
           If Len(F_snb) = 11 And Len(CStr(Val(Mid(F_snb, 3)))) = 9 Then Exit For
        Next
    End Function

Posting Permissions

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