+ Reply to Thread
Results 1 to 14 of 14

Complicated splitting cells into multiple cells for multiple cases

  1. #1
    Forum Contributor
    Join Date
    11-14-2021
    Location
    africa
    MS-Off Ver
    2016 & 2019
    Posts
    255

    Complicated splitting cells into multiple cells for multiple cases

    hello
    I would split cells for multiple cells . so split the items into cell are different counts . they contain 3,4,5,6 items and it's one space among the items .
    case1
    if the cells contain three items , then should split for each item into each cell separately as in row2,3 in sheet split .
    case2
    if the cells contain four items , then should be the first ,second items in column B and the third item should be in column C and the fourth item should be in column D see the row 4 in sheet split
    case3
    if the cells contain five items ,then should be the first ,second items in column B and third,fourth items should be in column C and the fifth item should be in column D see the row 4 in sheet split
    case4
    if the cells contain six items , then should be the first ,second items in column B and the third,fourth items should be in column C and the fifth,sixth items should be in column D see the row 5,6 in sheet split
    the result should be in the first sheet in the same range based on what I put in the second sheet and also I would add others sheets with the same structure . so the macro should be flexible .
    Attached Files Attached Files
    Last edited by Ali-M; 03-19-2022 at 04:49 AM.

  2. #2
    Forum Expert WideBoyDixon's Avatar
    Join Date
    10-03-2016
    Location
    Sheffield, UK
    MS-Off Ver
    365
    Posts
    2,182

    Re: Complicated splitting cells into multiple cells for multiple cases

    This should do what you're after and it should scale to more items:

    Please Login or Register  to view this content.
    WBD
    Office 365 on Windows 11, looking for rep!

  3. #3
    Forum Contributor
    Join Date
    11-14-2021
    Location
    africa
    MS-Off Ver
    2016 & 2019
    Posts
    255

    Re: Complicated splitting cells into multiple cells for multiple cases

    awesome ! this is exactly what I want and sorry about mistake the second item in row 3 for sheet SPLIT .I corrected and edited file . based on my explanation seem to you understood me what I want , but as I said
    would add others sheets with the same structure . so the macro should be flexible .
    so I would implement for specific sheets like (ITE,SH1,SH2,MN)
    last thing I would split the data just form the first time run the macro without show any error. your code split data repeatedly when run the macro for more than one time .

  4. #4
    Forum Expert WideBoyDixon's Avatar
    Join Date
    10-03-2016
    Location
    Sheffield, UK
    MS-Off Ver
    365
    Posts
    2,182

    Re: Complicated splitting cells into multiple cells for multiple cases

    You could add an extra line to prevent it from running twice on the same sheet:

    Please Login or Register  to view this content.
    WBD

  5. #5
    Forum Contributor
    Join Date
    11-14-2021
    Location
    africa
    MS-Off Ver
    2016 & 2019
    Posts
    255

    Re: Complicated splitting cells into multiple cells for multiple cases

    thanks , but how can be loop through theses sheets (ITE,SH1,SH2,MN) instead one sheet ITE as I said
    so I would implement for specific sheets like (ITE,SH1,SH2,MN)

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

    Cool Hello, try this !


    According to your attachment a VBA demonstration for starters (v2) :

    PHP Code: 
    Sub Demo1()
             
    Dim Ws As WorksheetVR&, SP&, C%
        For 
    Each Ws In Worksheets
              
    If Ws.[A1&"¤"&B1&"¤"&C1&"¤"&D1="S.N¤ITEM¤QTY¤"Then
            With Ws
    .[A1].CurrentRegion.Columns
                     
    .Item("C:D").Insert
                With 
    .Item("B:D")
                    
    Application.Trim(.Value2):  V(12) = "TYPE":  V(13) = "MODEL"
                
    For 2 To .Rows.Count
                        S 
    Split(V(R1))
                    If 
    UBound(S) > And UBound(S) < 6 Then
                            P 
    0
                        
    For 1 To 3
                            V
    (RC) = S(P)
                            If 
    UBound(S) - C Then P 1V(RC) = V(RC) & " " S(P)
                            
    1
                        Next
                    End 
    If
                
    Next
                   
    .Value2 V
                   
    .AutoFit
                End With
            End With
              End 
    If
        
    Next
    End Sub 
    ► Do you like it ? ► So thanks to click on bottom left star icon « Add Reputation » !
    Last edited by Marc L; 03-19-2022 at 09:01 PM. Reason: v2

  7. #7
    Forum Contributor
    Join Date
    11-14-2021
    Location
    africa
    MS-Off Ver
    2016 & 2019
    Posts
    255

    Re: Complicated splitting cells into multiple cells for multiple cases

    @Marc L excellent ! just I would implement your code for specific sheets(ITE,SH1,SH2,MN), not all of the sheets in workbook .
    how can achieve it,please?

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

    Arrow Re: Complicated splitting cells into multiple cells for multiple cases


    As my demonstration does very not treat all the sheets … Anyway you can add a test for specific sheets names or fill an array.

  9. #9
    Forum Contributor
    Join Date
    11-14-2021
    Location
    africa
    MS-Off Ver
    2016 & 2019
    Posts
    255

    Re: Complicated splitting cells into multiple cells for multiple cases

    As my demonstration does very not treat all the sheets
    I don't think so . if there is sheet doesn't contain like the first sheet it will populates error.
    I try mod your code from this
    Please Login or Register  to view this content.
    to this
    Please Login or Register  to view this content.
    but gives error object required in the same line

  10. #10
    Forum Expert sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2016 | 2019
    Posts
    13,234

    Re: Complicated splitting cells into multiple cells for multiple cases

    Please Login or Register  to view this content.
    Good Luck
    I don't presume to know what I am doing, however, just like you, I too started somewhere...
    One-day, One-problem at a time!!!
    If you feel I have helped, please click on the star to left of post [Add Reputation]
    Also....add a comment if you like!!!!
    And remember...Mark Thread as Solved.
    Excel Forum Rocks!!!

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

    Arrow Re: Complicated splitting cells into multiple cells for multiple cases


    Quote Originally Posted by Ali-M View Post
    I don't think so. if there is sheet doesn't contain like the first sheet it will populates error.
    So such error on my side !

    You misread : didn't you see the If Join codeline ? The reason why a specific sheets array seems useless …
    Last edited by Marc L; 03-19-2022 at 10:51 AM.

  12. #12
    Forum Contributor
    Join Date
    11-14-2021
    Location
    africa
    MS-Off Ver
    2016 & 2019
    Posts
    255

    Re: Complicated splitting cells into multiple cells for multiple cases

    I didn't misread . my knowladge in vba is too poor.
    this line
    HTML Code: 
    apply to every sheet in the workbook, as far as I know .
    didn't you see the If Join codeline ? The reason why a specific sheets array seems useless …
    if you see this seems useless . your code should work for the sheets contain the same structure as the first sheet .
    otherwise shouldn't show error mismatch when there is sheet not relating of data as the first sheet .
    and if you mean I have to change this line
    Please Login or Register  to view this content.
    show me how do that . sorry ! I can't do that myself

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

    Arrow Re: Complicated splitting cells into multiple cells for multiple cases


    So try the updated post #6 easy splitting demonstration …
    Last edited by Marc L; 03-19-2022 at 09:21 PM.

  14. #14
    Forum Contributor
    Join Date
    11-14-2021
    Location
    africa
    MS-Off Ver
    2016 & 2019
    Posts
    255

    Re: Complicated splitting cells into multiple cells for multiple cases

    @Marc L thanks for assistance

+ 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. Complicated product of multiple cells
    By Eazio in forum Excel General
    Replies: 16
    Last Post: 10-18-2016, 03:41 PM
  2. Splitting data from 1 - multiple cells
    By taylorcharley in forum Excel - New Users/Basics
    Replies: 2
    Last Post: 06-08-2015, 12:22 PM
  3. [SOLVED] Splitting Text into multiple cells
    By justin3681 in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 08-21-2012, 03:36 PM
  4. [SOLVED] Splitting Cells with multiple spaces
    By johnlynches in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 03-31-2012, 12:35 PM
  5. Replies: 2
    Last Post: 06-23-2011, 04:24 AM
  6. Splitting a Cell into multiple Cells
    By Royy in forum Excel General
    Replies: 8
    Last Post: 09-08-2010, 02:23 PM
  7. Replies: 7
    Last Post: 08-16-2010, 11:48 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