+ Reply to Thread
Results 1 to 7 of 7

Macro to separate long string of characters and several spaces into separate columns

  1. #1
    Forum Contributor
    Join Date
    01-09-2016
    Location
    USA,USA
    MS-Off Ver
    2016
    Posts
    1,192

    Macro to separate long string of characters and several spaces into separate columns

    I am looking basically to do a MID formula, but the value of the cell is like "A04AG605S206704561 BANNER" and I need the characters after the S (9 characters in) and then I need the name (Banner) I need these separated into columns. They will always start in A1, but not every row will have this data, Some may be "D123445678123". So I don't know if that is a front end thing, to only apply if the cell starts with A, or on the back end and after everything is separated into three columns, remove anything that doesn't have a value in column 3. This may also go 500 rows down, or 200 rows. Changes every day.

    Would it be best to first do a text to column type of thing and separate on the first space, then a mid type formula, but in a macro fashion. With 500+ rows, I am worried that it may use to much resources and because a different user will have the spreadsheet other than I and I can set it as a button versus afraid the formula gets adjusted.

    I have attached the spreadsheet which should be clearer than my explanation. Thanks!


    *edit, new workbook now without password!
    Attached Files Attached Files
    Last edited by taylorsm; 03-31-2017 at 10:42 AM.

  2. #2
    Forum Expert Arkadi's Avatar
    Join Date
    02-13-2014
    Location
    Smiths Falls, Ontario, Canada
    MS-Off Ver
    Office 365
    Posts
    5,059

    Re: Macro to separate long string of characters and several spaces into separate columns

    Hmmm... 2nd time in 2 days that someone posts a password protected file...
    Please help by:

    Marking threads as closed once your issue is resolved. How? The Thread Tools at the top
    Any reputation (*) points appreciated. Not just by me, but by all those helping, so if you found someone's input useful, please take a second to click the * at the bottom left to let them know

    There are 10 kinds of people in this world... those who understand binary, and those who don't.

  3. #3
    Forum Contributor
    Join Date
    01-09-2016
    Location
    USA,USA
    MS-Off Ver
    2016
    Posts
    1,192

    Re: Macro to separate long string of characters and several spaces into separate columns

    Damn sorry. Should be fixed.

  4. #4
    Forum Contributor
    Join Date
    01-09-2016
    Location
    USA,USA
    MS-Off Ver
    2016
    Posts
    1,192

    Re: Macro to separate long string of characters and several spaces into separate columns

    This is what I have come up with so far.
    But I guess I need to run a Range.TextToColumns first.


    Please Login or Register  to view this content.

  5. #5
    Forum Contributor
    Join Date
    01-09-2016
    Location
    USA,USA
    MS-Off Ver
    2016
    Posts
    1,192

    Re: Macro to separate long string of characters and several spaces into separate columns

    So I think I have it, or close enough. This is the longest i've gone on this site without a response.. odd. Friday i guess lol. Can anyone review my code and at least see if there is anything glaringly wrong?

    Please Login or Register  to view this content.

  6. #6
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Cool As a starter, try this !

    PHP Code: 
    Sub Macro1()
            
    Dim N&
            
    Application.ScreenUpdating False
        With Cells
    (1).CurrentRegion
               N 
    Application.CountBlank(.Columns(2))
            If 
    N Then
                    Cells
    (3).Resize(.Rows.Count).Formula "=ISBLANK(B1)"
                
    With .Resize(, 3).Rows
                     
    .Sort .Cells(3), xlAscendingHeader:=xlNo
                     Union
    (.Columns(3), .Item(.Count ":" & .Count)).Clear
                End With
            End 
    If
                .
    Columns(2).Cut Cells(3)
                .
    Columns(1).TextToColumns xlFixedWidthFieldInfo:=Array([{0,9}], [{9,2}], [{18,9}], [{32,2}])
        
    End With
            Application
    .ScreenUpdating True
    End Sub 
    Do you like it ? So thanks to click on bottom left star icon « Add Reputation » !

  7. #7
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Cool An alternative …

    SpecialCells method may have issue with big data but like here it is not the case :

    PHP Code: 
    Sub Macro1()
            
    Application.ScreenUpdating False
        With Cells
    (1).CurrentRegion.Columns
            
    If Application.CountBlank(.Item(2)) Then .Item(2).SpecialCells(xlCellTypeBlanks).EntireRow.Delete
            
    .Item(2).Cut Cells(3)
            .
    Item(1).TextToColumns xlFixedWidthFieldInfo:=Array([{0,9}], [{9,2}], [{18,9}], [{32,2}])
        
    End With
            Application
    .ScreenUpdating True
    End Sub 
    Do you like it ? So thanks to click on bottom left star icon « Add Reputation » !
    Last edited by Marc L; 03-31-2017 at 07:41 PM.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Problem separating a long string into four separate fields?
    By colgor in forum Excel Formulas & Functions
    Replies: 24
    Last Post: 06-15-2016, 03:04 PM
  2. [SOLVED] How to separate digits from string of numbers (must ignore characters)
    By mohit999 in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 01-28-2016, 03:12 PM
  3. [SOLVED] How can I exctract numbers from a string of characters in a separate column ?
    By Renzo Isola in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 05-27-2013, 11:15 PM
  4. [SOLVED] How to separate names in a long cell string
    By mondello in forum Excel General
    Replies: 5
    Last Post: 08-02-2012, 02:59 AM
  5. How to Separate Chunks of Characters and put them in separate Columns
    By crisshinn in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 03-08-2011, 10:16 AM
  6. search for specific characters in text string and separate them out
    By neowok in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 06-09-2008, 09:21 AM
  7. Separate characters in a string
    By viadisky in forum Excel General
    Replies: 2
    Last Post: 02-01-2006, 01:35 PM

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.6.0 RC 1