+ Reply to Thread
Results 1 to 11 of 11

Breaking down a list into more.

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    05-05-2004
    MS-Off Ver
    Office 365
    Posts
    651

    Breaking down a list into more.

    I have been handed a hot pile of steaming yuck and need some help with the final part of it.
    In the attached example you can see row 2-4 had data for 3 separate items. Column G is my achilleas heel now.
    For example Col 2 needs to be broken down into 4 SEPARATE rows line 11-14.
    This file sometimes will have only 1 or 30 in G so its not always going to be 4. The actual file is HUGE so its not something I would like to do manually at this point.
    Attached Files Attached Files

  2. #2
    Forum Expert CK76's Avatar
    Join Date
    06-16-2015
    Location
    ONT, Canada
    MS-Off Ver
    MS365 Apps for enterprise
    Posts
    5,913

    Re: Breaking down a list into more.

    Since you have Office 365, use Power Query.

    Assuming that you don't need to keep the hidden column ([UPC]).

    Sample M code:
    let
        Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
        #"Changed Type" = Table.TransformColumnTypes(Source,{{"STOCK VN CODE", type any}, {"Qty Avai", type any}, {"STOCK CN CODE1", type text}, {"Qty Avai2", Int64.Type}, {"SKU", type text}, {"FP FRAME SKKU", type text}, {"FP SKU", type text}, {"UPC", type text}, {"PRODUCT NAME", type text}, {"QTY Available", Int64.Type}}),
        #"Added Custom" = Table.AddColumn(#"Changed Type", "Custom", each Text.Split([FP SKU],"#(lf)")),
        #"Removed Columns" = Table.RemoveColumns(#"Added Custom",{"FP SKU", "UPC"}),
        #"Reordered Columns" = Table.ReorderColumns(#"Removed Columns",{"STOCK VN CODE", "Qty Avai", "STOCK CN CODE1", "Qty Avai2", "SKU", "FP FRAME SKKU", "Custom", "PRODUCT NAME", "QTY Available"}),
        #"Renamed Columns" = Table.RenameColumns(#"Reordered Columns",{{"Custom", "FP SKU"}}),
        #"Expanded FP SKU" = Table.ExpandListColumn(#"Renamed Columns", "FP SKU"),
        #"Changed Type1" = Table.TransformColumnTypes(#"Expanded FP SKU",{{"FP SKU", type text}})
    in
        #"Changed Type1"
    Sample file attached.
    Attached Files Attached Files
    ?Progress isn't made by early risers. It's made by lazy men trying to find easier ways to do something.?
    ― Robert A. Heinlein

  3. #3
    Valued Forum Contributor
    Join Date
    07-14-2017
    Location
    Poland
    MS-Off Ver
    Office 2010
    Posts
    528

    Re: Breaking down a list into more.

    Try.
    Sub test()
        Dim a(), af, v
        Dim i As Integer, ii As Integer, rw As Integer
        Dim d As Object
        Dim ms As String
        
        With Sheets("INDIVIDUAL INVENTORY")
            a = .[g1].CurrentRegion.Value
            ReDim af(1 To 5000, 1 To 8)
            For i = 2 To UBound(a)
                v = Split(a(i, 7), Chr(10))
                For ii = 0 To UBound(v)
                    rw = rw + 1
                    af(rw, 1) = a(i, 3): af(rw, 2) = a(i, 4): af(rw, 3) = a(i, 5)
                    af(rw, 4) = a(i, 6): af(rw, 5) = v(ii): af(rw, 7) = a(i, 9): af(rw, 8) = a(i, 10)
                Next
            Next
            With .[a10].CurrentRegion.Offset(1)
                .ClearContents
                .Columns("c").Resize(rw, UBound(af, 2)).Value = af
            End With
        End With
    End Sub
    Attached Files Attached Files
    Best Regards,
    Maras.

  4. #4
    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
    44,767

    Re: Breaking down a list into more.

    An, late to the party, another option to expand the data in-situ.

    Option Explicit
    
    Sub sSplitCells()
    
    Dim lLR As Long, i As Long
    Dim vArray
    Dim rTemp As Range, cell As Range
    
    Application.ScreenUpdating = False
    
    ' determine last row of data
    lLR = Range("G" & Rows.Count).End(xlUp).Row
    
    ' expand rows
    For i = lLR To 2 Step -1
        vArray = Split(Cells(i, "G"), Chr(10))
        If UBound(vArray) > 0 Then
            Cells(i, "G").Offset(1).Resize(UBound(vArray)).EntireRow.Insert
            Cells(i, "G").Offset(0).Resize(UBound(vArray) + 1) = Application.WorksheetFunction.Transpose(vArray)
        End If
    Next 'i
    
    ' recalculate last row of data
    lLR = Range("G" & Rows.Count).End(xlUp).Row
    
    ' fill blank cells
    Set rTemp = Range("A3:J" & lLR).SpecialCells(xlCellTypeBlanks)
    Range("A3:J" & lLR).SpecialCells(xlCellTypeBlanks).FormulaR1C1 = _
            "=IF(R[-1]C="""","""",R[-1]C)"
    
    ' convert previously blank cell formulae to values
    For Each cell In rTemp
        With cell
            .Value = .Value
        End With
    Next 'cell
    
    Application.ScreenUpdating = True
    
    End Sub
    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


  5. #5
    Forum Guru Bo_Ry's Avatar
    Join Date
    09-10-2018
    Location
    Thailand
    MS-Off Ver
    MS 365
    Posts
    7,213

    Re: Breaking down a list into more.

    Power Query with UPC

    let
        Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
        AddT = Table.AddColumn(Source, "T", each Table.FromColumns({Text.Split([FP SKU],"#(lf)"),Text.Split([UPC],"#(lf)")},{"FP SKU","UPC"})),
        Removed = Table.RemoveColumns(AddT,{"FP SKU", "UPC"}),
        ExpandedT = Table.ExpandTableColumn(Removed, "T", {"FP SKU", "UPC"}, {"FP SKU", "UPC"}),
        ReorderedColumns = Table.ReorderColumns(ExpandedT,List.InsertRange(List.Difference(Table.ColumnNames(Source),{"FP SKU", "UPC"}),6,{"FP SKU", "UPC"}))
    in
        ReorderedColumns
    Attached Files Attached Files

  6. #6
    Forum Contributor
    Join Date
    05-05-2004
    MS-Off Ver
    Office 365
    Posts
    651

    Re: Breaking down a list into more.

    This is all amazing guys, thank you SO much for your help with this. For ME, the best one of these to use would be TMS, but again, thank you too all.

    I do have one last question that is related to this thread.

        Range("D2").Select
        Selection.AutoFill Destination:=Range("D2:D1000"), Type:=xlFillDefault
    How would this be re-written so that D1000 is the variable "lLR"?

  7. #7
    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
    44,767

    Re: Breaking down a list into more.

    You're welcome.

    Range("D2").AutoFill Destination:=Range("D2:D" & lLR), Type:=xlFillDefault


    If you are satisfied with the solution(s) provided, please mark your thread as Solved.


    New quick method:
    Select Thread Tools-> Mark thread as Solved. To undo, select Thread Tools-> Mark thread as Unsolved.

    Or you can use this way:

    How to mark a thread Solved
    Go to the first post
    Click edit
    Click Go Advanced
    Just below the word Title you will see a dropdown with the word No prefix.
    Change to Solved
    Click Save


    You may also want to consider thanking those people who helped you by clicking on the little star at the bottom left of their reply to your question.
    Last edited by TMS; 02-02-2021 at 12:13 PM.

  8. #8
    Forum Contributor
    Join Date
    05-05-2004
    MS-Off Ver
    Office 365
    Posts
    651

    Re: Breaking down a list into more.

    RATS!!!!! TMS, I JUST realized that it's BOTH columns G AND H that need to be broken down. The good news is that G and H coincide with each other so there will always be an H to go with the G.... Does that make sense?

    I tried to alter the code myself but was unsuccessful. Help, please.....

  9. #9
    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
    44,767

    Re: Breaking down a list into more.

    This should do it:

    Option Explicit
    
    Sub sSplitCells_V2()
    
    Dim wsf As WorksheetFunction: Set wsf = WorksheetFunction
    Dim lLR As Long, i As Long
    Dim vArray, vArrayH
    Dim rTemp As Range, cell As Range
    
    Application.ScreenUpdating = False
    
    ' determine last row of data
    lLR = Range("G" & Rows.Count).End(xlUp).Row
    
    ' expand rows
    For i = lLR To 2 Step -1
        vArray = Split(Cells(i, "G"), Chr(10))
        vArrayH = Split(Cells(i, "H"), Chr(10))
        If UBound(vArray) > 0 Then
            Cells(i, "G").Offset(1).Resize(UBound(vArray)).EntireRow.Insert
            Cells(i, "G").Offset(0).Resize(UBound(vArray) + 1) = wsf.Transpose(vArray)
            Cells(i, "H").Offset(0).Resize(UBound(vArrayH) + 1).NumberFormat = "@"
            Cells(i, "H").Offset(0).Resize(UBound(vArrayH) + 1) = wsf.Transpose(vArrayH)
        End If
    Next 'i
    
    ' recalculate last row of data
    lLR = Range("G" & Rows.Count).End(xlUp).Row
    
    ' fill blank cells
    Set rTemp = Range("A3:J" & lLR).SpecialCells(xlCellTypeBlanks)
    Range("A3:J" & lLR).SpecialCells(xlCellTypeBlanks).FormulaR1C1 = _
            "=IF(R[-1]C="""","""",R[-1]C)"
    
    ' convert previously blank cell formulae to values
    For Each cell In rTemp
        With cell
            .Value = .Value
        End With
    Next 'cell
    
    Application.ScreenUpdating = True
    
    End Sub

  10. #10
    Forum Contributor
    Join Date
    05-05-2004
    MS-Off Ver
    Office 365
    Posts
    651

    Re: Breaking down a list into more.

    YEP! that worked! Thank you so much!

  11. #11
    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
    44,767

    Re: Breaking down a list into more.

    You're welcome. Thanks for the rep.

+ 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] Do While loop not breaking?
    By dcwan in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 03-31-2020, 05:20 PM
  2. Breaking Dynamic list prices
    By malcoski in forum Excel General
    Replies: 8
    Last Post: 11-16-2018, 12:30 PM
  3. [SOLVED] Breaking hierarchical list into separate columns
    By billyjo182 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 06-10-2017, 03:55 AM
  4. Replies: 2
    Last Post: 11-24-2016, 02:35 PM
  5. Why is this code breaking...
    By pasqualebaldi in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 02-17-2015, 03:02 PM
  6. breaking a tie
    By drltr6 in forum Excel General
    Replies: 5
    Last Post: 05-29-2009, 05:19 PM
  7. Breaking up a long list into different worksheets
    By blurtoad in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 08-31-2007, 06:29 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