+ Reply to Thread
Results 1 to 4 of 4

Split Text File Data

  1. #1
    Registered User
    Join Date
    03-19-2018
    Location
    Ottawa Canada
    MS-Off Ver
    2013
    Posts
    1

    Split Text File Data

    Hello,
    I've built a macro to extract a txt file and create a separe worksheet for each scenario (only blue, only red & both colours - based on columns "A" & "B"). I also wanted to keep empty rows between different records in each worksheet. When I run the macro, it gets stack and no details are created under each worksheet. My macro and the input file are attached.

    Any help would be appreciated.
    Cheers,
    Goropd
    Attached Files Attached Files

  2. #2
    Forum Expert Olly's Avatar
    Join Date
    09-10-2013
    Location
    Darlington, UK
    MS-Off Ver
    Excel 2016, 2019, 365
    Posts
    6,284

    re: Split Text File Data

    Your post does not comply with Rule 1 of our Forum RULES. Your post title should accurately and concisely describe your problem, not your anticipated solution.

    Use terms appropriate to a Google search. Poor thread titles, like Please Help, Urgent, Need Help, Formula Problem, Code Problem, and Need Advice will be addressed according to the OP's experience in the forum: If you have less than 10 posts, expect (and respond to) a request to change your thread title. If you have 10 or more posts, expect your post to be locked, so you can start a new thread with an appropriate title.

    To change a Title go to your first post, click EDIT then Go Advanced and change your title, if 2 days have passed ask a moderator to do it for you.
    let Source = #table({"Question","Thread", "User"},{{"Answered","Mark Solved", "Add Reputation"}}) in Source

    If I give you Power Query (Get & Transform Data) code, and you don't know what to do with it, then CLICK HERE

    Walking the tightrope between genius and eejit...

  3. #3
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    re: Split Text File Data

    Hello goropd,

    I have added this macro to the attached workbook. Let me know if this needs any modification.

    Please Login or Register  to view this content.
    Attached Files Attached Files
    Sincerely,
    Leith Ross

    Remember To Do the Following....

    1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.
    2. Thank those who have helped you by clicking the Star below the post.
    3. Please mark your post [SOLVED] if it has been answered satisfactorily.


    Old Scottish Proverb...
    Luathaid gu deanamh maille! (Rushing causes delays!)

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

    Cool Hi ! Another way …


    As I'm not sure to well copy your need without any expected result workbook attachment
    but as a starter just with Excel inner features like text convert, filter, formula, sort, …

    PHP Code: 
    Sub Demo1()
        
    Dim VF&, Ws As WorksheetC&, R&
            
    Application.GetOpenFilename("Text Files (*.txt),*.txt")
            If 
    False Then Exit Sub
               F 
    Application.SheetsInNewWorkbook
             Application
    .ScreenUpdating False
             Application
    .SheetsInNewWorkbook 3
             Set Ws 
    Workbooks.Add.Worksheets(1)
             
    Application.SheetsInNewWorkbook F
        With Workbooks
    .Open(V).Worksheets(1)
                
    Ws.[A1].Value LTrim(.[A1].Text)
               .
    UsedRange.TextToColumns xlFixedWidthxlTextQualifierNoneDecimalSeparator:="."_
                FieldInfo
    :=Array([{0,2}], [{9,2}], [{22,2}], [{29,2}], [{43,2}], [{51,4}], [{65,1}], [{78,1}], [{97,2}], [{105,2}])
                
    = .[A1].End(xlDown).Row
                C 
    = .UsedRange.Columns.Count 1
                R 
    = .UsedRange.Rows.Count
                V 
    = .Cells(F1).Text
            With Range
    (.Cells(2C), .Cells(RC))
                .
    Formula Replace("=OR(AND(A2="""",OR(A1="""",A1=""#"")),A2=""#"")""#"V)
                .
    Formula = .Value
            End With
                Range
    (.Cells(F1), .Cells(RC)).Sort .Cells(FC), xlAscendingHeader:=xlYes
                R 
    = .UsedRange.Columns(C).Find(FalseSearchDirection:=xlPrevious).Row
                Range
    (.Cells(F1), .Cells(R2)).Copy Ws.[B1]
               .
    Parent.Close False
        End With
        
    For Each V In [{"BLUE","RED"}]
            
    With Ws.Parent.Worksheets(- ("RED"))
                 
    Ws.UsedRange.Columns(2).AutoFilter 1VxlOr""
                 
    Ws.UsedRange.Copy .[A1]
                 
    Range(.Cells(24), .Cells(.UsedRange.Rows.Count4)).Formula "=AND(B2="""",B1="""")"
                
    .UsedRange.Sort .Cells(4), xlAscendingHeader:=xlYes
                
    .UsedRange.Columns(4).Clear
                
    .Columns(1).AutoFit
                
    .Name V
            End With
        Next
                 Ws
    .[A1].AutoFilter
                 Ws
    .Columns(1).AutoFit
                 Ws
    .Name "BOTH"
             
    Set Ws Nothing
             Application
    .ScreenUpdating True
    End Sub 
    Do you like it ? So thanks to click on bottom left star icon « Add Reputation » !

+ 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. [SOLVED] Automatically split file based on data
    By Tapyr in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 10-24-2017, 09:56 PM
  2. Replies: 4
    Last Post: 11-11-2015, 03:00 PM
  3. Import text file and split data into specific sheets with Applet names
    By swethachepur in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 03-22-2014, 09:07 AM
  4. [SOLVED] VBA Split Data and Move to targeted named file from master file
    By breadwinner in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 06-19-2013, 01:06 PM
  5. Import text file into excel and split data in specific sheets
    By chirilaionut in forum Excel Programming / VBA / Macros
    Replies: 17
    Last Post: 06-03-2013, 07:04 AM
  6. Split Text File
    By erock24 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 04-26-2010, 02:42 PM
  7. [SOLVED] Split text without using data-text to columns
    By Jambruins in forum Excel General
    Replies: 7
    Last Post: 01-21-2006, 10:20 AM

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