+ Reply to Thread
Results 1 to 14 of 14

Split Text To Column based on Indents

  1. #1
    Forum Contributor
    Join Date
    10-24-2012
    Location
    Chicago
    MS-Off Ver
    O365
    Posts
    311

    Split Text To Column based on Indents

    Hello,

    I have the following file (attached) where there is code that breaks up indentation in one column to multiple columns based on the indentation. It is working great with the Entity Tab. When I copy the code to use for one of the other tabs it no longer works. Can someone help me resolve that? I've tried a number of attempts to fix but am having no luck.

    Please Login or Register  to view this content.
    Attached Files Attached Files

  2. #2
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    48,509

    Re: Split Text To Column based on Indents

    You probably need to change this line
    Please Login or Register  to view this content.
    to refer to the other sheet(s).
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


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

    Arrow Re: Split Text To Column based on Indents


    Hello, you forgot to indicate where your VBA procedure is located as your attachment is just 'VBA empty' ...

  4. #4
    Forum Contributor
    Join Date
    10-24-2012
    Location
    Chicago
    MS-Off Ver
    O365
    Posts
    311

    Re: Split Text To Column based on Indents

    I have two subs as an example where I have with Sheets UD3 and it fails for that sheet.

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

    Exclamation Re: Split Text To Column based on Indents


    As my post #3 still needs an appropriate answer ...

  6. #6
    Forum Contributor
    Join Date
    10-24-2012
    Location
    Chicago
    MS-Off Ver
    O365
    Posts
    311

    Re: Split Text To Column based on Indents

    Trying to post again. It is an xlsm file. Not sure why it wouldn't post that way.
    Attached Files Attached Files

  7. #7
    Forum Contributor
    Join Date
    10-24-2012
    Location
    Chicago
    MS-Off Ver
    O365
    Posts
    311

    Re: Split Text To Column based on Indents

    It should show up in Module 1.

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

    Arrow Re: Split Text To Column based on Indents


    So, as yet exposed in post #2, if you launch manually the VBA procedure from the source indent worksheet
    then just replace the hardcoded worksheet reference with the statement ActiveSheet obviously ...

  9. #9
    Forum Contributor
    Join Date
    10-24-2012
    Location
    Chicago
    MS-Off Ver
    O365
    Posts
    311

    Re: Split Text To Column based on Indents

    The code is running either way without error. The result is not showing as expected. It shows data split to columns for the Entity tab however when I try it on other tabs I just see headers without data beneath. Thanks for the help this far.

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

    Arrow Re: Split Text To Column based on Indents


    Well in this case the data seem to not be the same structure between Entity and other worksheets
    so you need to find what differs in order to revise the logic of 'your' code ...

  11. #11
    Forum Contributor
    Join Date
    10-24-2012
    Location
    Chicago
    MS-Off Ver
    O365
    Posts
    311

    Re: Split Text To Column based on Indents

    I never stated it was mine which is why I was asking for help. It just so happened that it worked on the first tab I attempted it on and didn't on the others. Thanks again for your help.

  12. #12
    Forum Contributor
    Join Date
    10-24-2012
    Location
    Chicago
    MS-Off Ver
    O365
    Posts
    311

    Re: Split Text To Column based on Indents

    Thanks for the tip. Adjusting the if indent is less than # has it working. Just not as clean as the Entity code.

  13. #13
    Forum Contributor
    Join Date
    10-24-2012
    Location
    Chicago
    MS-Off Ver
    O365
    Posts
    311

    Re: Split Text To Column based on Indents

    Here is the adjusted code that has it working thanks to the tip. There were three spots that needed to be updated. Added comments and then added some remove duplicate code on the columns so that I can create dimensions more quickly for an application build.

    Please Login or Register  to view this content.

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

    Cool Try this ...


    Well done !

    But duplicate a code tab for other tabs is not necessary
    just passing the worksheet(s) name(s) to a procedure like
    according to your post #6 attachment these 3 VBA demonstrations just calling the SplitSheet procedure :

    PHP Code: 
    Sub SplitSheet(ParamArray S())
        
    Dim WC%, L%, R&, T$(), N&
            
    Application.ScreenUpdating False
        
    For Each W In S
            C 
    = -1:  0:  1
        With Sheets
    (W).[A1].CurrentRegion.Rows
            ReDim T
    (1 To .Count99)
        For 
    2 To .Count
            With 
    .Cells(N1)
              If .
    IndentLevel L Then
                L 
    = .IndentLevel
              
    Else
                
    1
                
    For 0 To .IndentLevel 1:  T(RL) = T(1L):  Next
              End 
    If
                
    T(RL) = .Value
                
    If C Then T(1L) = "Level #" LL
            End With
        Next
            W 
    "Split"
            
    If Evaluate("ISREF('" "'!A1)"Then With Sheets(W): .UsedRange.Clear: .ActivateEnd With _
                                                 
    Else Sheets.Add .ParentActiveSheet.Name W
        End With
        With 
    [A1].Resize(R1).Columns
            
    .Value T
             N 
    2
         
    For 1 To C
             N 
    2
            
    .Item(L).Resize(, 2).Copy .Item(N)
            .
    Item(N).Resize(, 2).RemoveDuplicates Array(12), 1
         Next
        End With
            ActiveSheet
    .UsedRange.Columns.AutoFit
            With ActiveWindow
    :  .SplitColumn 0:  .SplitRow 1:  .FreezePanes True:  End With
        Next
            Application
    .ScreenUpdating True
    End Sub

    Sub SplitEntity
    ()
        
    SplitSheet "Entity"
    End Sub

    Sub SplitScenario
    ()
        
    SplitSheet "Scenario"
    End Sub

    Sub SplitSheets
    ()
        
    SplitSheet "Entity""Scenario""Flow"
    End Sub 
    ► Do you like it ? ► So thanks to click on bottom left star icon ? Add Reputation ? !
    Last edited by Marc L; 09-22-2022 at 10:20 AM. Reason: optimization ...

+ 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. Removing all indents from a column
    By davidx in forum Excel General
    Replies: 4
    Last Post: 01-13-2021, 10:25 PM
  2. [SOLVED] Concatenate Text in Column B Split in Multiple Rows for Each Number in Column A
    By zaska in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 09-23-2020, 03:51 AM
  3. Split a column based on text
    By xBxW in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 06-19-2018, 11:42 AM
  4. Replies: 9
    Last Post: 01-04-2017, 03:35 PM
  5. Need Macro code to split data split in 7 sheets based on variable rows in column A
    By Alija_21 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 12-31-2015, 08:03 AM
  6. Split row into multiple row based on column text
    By chicagoland8 in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 03-10-2014, 04:20 PM
  7. How Do I Split Text Based Upon Two Values To Split
    By HowdeeDoodee in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 11-08-2012, 05:05 AM

Tags for this Thread

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