Consulting

Results 1 to 6 of 6

Thread: HOW TO STRIP OUT ONLY RELEVANT DATA FROM A STRING BY USING FORMULA OR VBA

  1. #1
    VBAX Newbie
    Joined
    Sep 2015
    Posts
    3
    Location

    HOW TO STRIP OUT ONLY RELEVANT DATA FROM A STRING BY USING FORMULA OR VBA

    Hello, I have just recently got into VBA and am having difficulty getting the relevant data from the below text string as the length varies.
    I am looking to get the bold text from the below strings

    ie 9600, 24 3150,12975 copied into column B

    Can somebody suggest a formula, or alternatively a vba code to strip out the relevant numbers bolded below and copy in the data into the next column.
    There is a fixed character length at the right and left of the relevant data.

    COLUMN A
    Basis, Klasse ("OPT, 254856, DE0008469008, 846949, 20.06.2016, 9600, C") could not be determined
    Basis, Klasse ("OPT, 254857, DE0005552004, 555200, 20.06.2016, 24, C") could not be determined
    Basis, Klasse ("OPT, 254892, EU0009658145, 965239, 19.10.2015, 3150, C") could not be determined
    Basis, Klasse ("OPT, 254893, EU0009658145, 965239, 19.10.2015, 12975, P") could not be determined



  2. #2
    VBAX Guru mancubus's Avatar
    Joined
    Dec 2010
    Location
    "Where I lay my head is home" :D
    Posts
    2,644
    if the texts in col A are comma separated and the bit that will be extracted is the bit before last comma, try:

    Sub vbax_53848_xtract_nums_comma_delimeter()
    
        Dim i As Long
        Dim CommaSplitted
        
        With Worksheets("Sheet1") 'change Sheet1 to suit
            For i = 2 To Cells(.Rows.Count, 1).End(xlUp).Row
                CommaSplitted = Split(.Cells(i, 1).Value, ",")
                .Cells(i, 2).Value = WorksheetFunction.Trim(CommaSplitted(UBound(CommaSplitted) - 1))
            Next i
        End With
    
    End Sub
    PLS DO NOT PM; OPEN A THREAD INSTEAD!!!

    1) Posting Code
    [CODE]PasteYourCodeHere[/CODE]
    (or paste your code, select it, click # button)

    2) Uploading File(s)
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) (multiple files can be selected while holding Ctrl key) / Upload Files / Done
    Replace company specific / sensitive / confidential data. Include so many rows and sheets etc in the uploaded workbook to enable the helpers visualize the data and table structure. Helpers do not need the entire workbook.

    3) Testing the Codes
    always back up your files before testing the codes.

    4) Marking the Thread as Solved
    from Thread Tools (on the top right corner, above the first message)

  3. #3
    VBAX Newbie
    Joined
    Sep 2015
    Posts
    3
    Location
    Many thanks mancubus, I really appreciate you help in this matter.
    There is absolutely no way I would have figured that code out without your help.

    I have one slight issue remaining, which you may be able to help with?

    For some reason the code doesn't seem to work for the first 'string' in the column A, it only works for all subsequent rows.

    Do you have any suggestions on how to correct this?

    Results of code
    Basis, Klasse ("OPT, 254856, DE0008469008, 846949, 20.06.2016, 9600, C") could not be determined
    Basis, Klasse ("OPT, 254857, DE0005552004, 555200, 20.06.2016, 24, C") could not be determined 24
    Basis, Klasse ("OPT, 254892, EU0009658145, 965239, 19.10.2015, 3150, C") could not be determined 3150
    Basis, Klasse ("OPT, 254893, EU0009658145, 965239, 19.10.2015, 12975, P") could not be determined 12975

  4. #4
    VBAX Guru mancubus's Avatar
    Joined
    Dec 2010
    Location
    "Where I lay my head is home" :D
    Posts
    2,644
    You are welcome.

    I assumed cell A1 contained a column header...

    Change
    For i = 2
    To
    For i = 1
    PLS DO NOT PM; OPEN A THREAD INSTEAD!!!

    1) Posting Code
    [CODE]PasteYourCodeHere[/CODE]
    (or paste your code, select it, click # button)

    2) Uploading File(s)
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) (multiple files can be selected while holding Ctrl key) / Upload Files / Done
    Replace company specific / sensitive / confidential data. Include so many rows and sheets etc in the uploaded workbook to enable the helpers visualize the data and table structure. Helpers do not need the entire workbook.

    3) Testing the Codes
    always back up your files before testing the codes.

    4) Marking the Thread as Solved
    from Thread Tools (on the top right corner, above the first message)

  5. #5
    VBAX Newbie
    Joined
    Sep 2015
    Posts
    3
    Location
    Thank you, perfect now, much appreciated

  6. #6
    VBAX Guru mancubus's Avatar
    Joined
    Dec 2010
    Location
    "Where I lay my head is home" :D
    Posts
    2,644
    you are welcome.

    please mark the thread as "solved" from Thread Tools dropdown (which is above the top right corner of the first messsage) for future references...
    PLS DO NOT PM; OPEN A THREAD INSTEAD!!!

    1) Posting Code
    [CODE]PasteYourCodeHere[/CODE]
    (or paste your code, select it, click # button)

    2) Uploading File(s)
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) (multiple files can be selected while holding Ctrl key) / Upload Files / Done
    Replace company specific / sensitive / confidential data. Include so many rows and sheets etc in the uploaded workbook to enable the helpers visualize the data and table structure. Helpers do not need the entire workbook.

    3) Testing the Codes
    always back up your files before testing the codes.

    4) Marking the Thread as Solved
    from Thread Tools (on the top right corner, above the first message)

Tags for this Thread

Posting Permissions

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