Page 1 of 2 12 LastLast
Results 1 to 10 of 18

Thread: Extract numbers from text into multiple columns

  1. #1
    Junior Member
    Join Date
    Sep 2015
    Posts
    10
    Rep Power
    0

    Red face Extract numbers from text into multiple columns

    I hope i am not repeating someone else's question but i couldn't find the answer to my question -

    I have a column of text strings that i need to extract the numbers out of each text string but not as a long number, instead into separate columns in order to them perform a calculation from the various numbers eg:

    NUMBERS FROM TEXT.jpg

    I have columns A & B and need to extract the numbers from either column A or B into columns C, D, E & F in order to perform a calculation of the amount of film used of the different types. Column C could read the micron thickness from Column A rather than the 2 digit code in Column B as this is just for sorting not calculating.

    Thank you in advance for saving me a lot of time - I currently manually extract the numbers each month and there are about 1,000 rows each time.

  2. #2
    Junior Member
    Join Date
    Sep 2015
    Posts
    10
    Rep Power
    0
    Looking at the attachment i am not sure the data is readable so here it is again, hopefully more legible.
    NUMBERS FROM TEXT 11pt.jpg

  3. #3
    Senior Member
    Join Date
    Jun 2012
    Posts
    337
    Rep Power
    12
    Please post a sample workbook.

  4. #4
    Junior Member
    Join Date
    Sep 2015
    Posts
    10
    Rep Power
    0
    Please find attached sample workbook
    Attached Files Attached Files

  5. #5
    Senior Member
    Join Date
    Jun 2012
    Posts
    337
    Rep Power
    12
    Code:
    Sub M_snb()
        Columns(2).SpecialCells(2).TextToColumns Range("C2"), xlFixedWidth, , , , , , , , , Array(Array(0, 9), Array(2, 1), Array(4, 9), Array(7, 1), Array(11, 1), Array(15, 1), Array(16, 9))
    End Sub

  6. #6
    Junior Member
    Join Date
    Sep 2015
    Posts
    10
    Rep Power
    0
    snb, sorry how do i enter this code into the spreadsheet?

  7. #7
    Junior Member
    Join Date
    Sep 2015
    Posts
    10
    Rep Power
    0
    I have entered the code and run it but it seems to leave an empty cell?

  8. #8
    Forum Guru Rick Rothstein's Avatar
    Join Date
    Feb 2012
    Posts
    659
    Rep Power
    13
    Does this macro do what you want...
    Code:
    Sub SplitOutNumbers() Dim R As Long, X As Long, LastRow As Long, Text As Variant, Results As Variant LastRow = Cells(Rows.Count, "A").End(xlUp).Row For R = 1 To LastRow Text = Cells(R, "B").Value For X = 1 To Len(Text) If Mid(Text, X, 1) Like "[!0-9]" Then Mid(Text, X) = " " Next Text = Split(Application.Trim(Text), " ", 2) Cells(R, "C").Resize(, 4).Value = Array(Text(0), Mid(Text(1), 4), Mid(Text(1), 5, 4), Right(Text(1), 1)) Next End Sub
    Last edited by Rick Rothstein; 10-03-2015 at 12:02 AM.

  9. #9
    Junior Member
    Join Date
    Sep 2015
    Posts
    10
    Rep Power
    0
    Thanks Rick for trying but assuming I have entered it correctly and run it correctly it came out as attached. At the moment I have spent most of this week writing a 50,000 line, 6 column look up table to try to cover every eventuality but this is a somewhat time consuming way and not fool proof, and this only solves one set of data and I have another 2 to solve, so if you can find a way I would be very grateful!
    Attached Files Attached Files

  10. #10
    Forum Guru Rick Rothstein's Avatar
    Join Date
    Feb 2012
    Posts
    659
    Rep Power
    13
    [QUOTE=Giraffe;9547]Thanks Rick for trying but assuming I have entered it correctly and run it correctly it came out as attached. At the momen
    Quote Originally Posted by Giraffe View Post
    Thanks Rick for trying but assuming I have entered it correctly and run it correctly it came out as attached.
    The reason the code did not work for you is because I designed it for this (which came from the workbook you attached to Message #4)...


    A B C D E F
    1 100mic Gloss Film 1000mm x 100m on 78mm core FP22GLO100001003K 22 1000 100 3
    2 100mic Gloss Film 1400mm x 1400m x 78mm core FP22GLO140014003F 22 1400 1400 3
    3 125mic Gloss Film 230mm x 60m on 58mm core FP23GLO023000602 23 230 60 2
    4 125mic Gloss Film 230mm x 100m on 58mm core FP23GLO023001002OUT 23 230 100 2
    5 75mic Ultra Matt Film 110mm x 1000m on 78mm core FR12MAT011010003 12 110 1000 3


    but this is from the workbook you attached to Message #9 which you say my code did not work for...


    A B C D E F
    1
    UBG315X500X77 ULTRABOND GLOSS 315mm 500m 77mm core 315 77 77 7
    2
    UBG315X500X77 ULTRABOND GLOSS 315mm 500m 77mm core 315 77 77 7
    3 UBM315X500X77 ULTRABOND MATT 315mm 500m 77mm core 315 77 77 7


    Does anything look different about those two layouts to you? Because they sure look different to me!

    Now, what does your data layout actually look like... the first or second table above?

Similar Threads

  1. Extract Only Numbers & TEXT From Text String
    By mahmoud-lee in forum Excel Help
    Replies: 9
    Last Post: 11-02-2013, 02:49 PM
  2. Replies: 4
    Last Post: 05-01-2013, 09:49 PM
  3. Replies: 2
    Last Post: 09-24-2012, 09:20 PM
  4. Extract numbers from alphanumeric values
    By tushar.tarafdar in forum Excel Help
    Replies: 3
    Last Post: 09-20-2012, 10:16 PM
  5. VBA Function To Extract Decimal Numbers
    By PcMax in forum Excel Help
    Replies: 7
    Last Post: 11-19-2011, 09:42 PM

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
  •