+ Reply to Thread
Results 1 to 7 of 7

Cleaning up data

Hybrid View

aldek Cleaning up data 04-20-2012, 05:28 PM
Mallycat Re: Cleaning up data 04-20-2012, 06:47 PM
aldek Re: Cleaning up data 04-23-2012, 12:37 PM
jindon Re: Cleaning up data 04-23-2012, 04:23 PM
aldek Re: Cleaning up data 04-23-2012, 06:06 PM
jindon Re: Cleaning up data 04-23-2012, 07:42 PM
nilem Re: Cleaning up data 04-24-2012, 12:24 AM
  1. #1
    Registered User
    Join Date
    06-06-2011
    Location
    Houston, Texas
    MS-Off Ver
    Excel 2007
    Posts
    23

    Cleaning up data

    Hello everyone,
    I have a file which lists inventory by store. The problem is, the store numbers are listed first, then the inventory is listed underneath. Each item is seperated by a SKU (unique identifier). The width of each inventory/store listing is either 13 or 14 units wide.
    I am trying to get all of this information in a format which is one line tall and about 200 lines wide.
    For example:
    SKU, Description, Size, Inventory Quantity Store 00, Inventory Quantity Store 01, Inventory Quantity Store 02, ...Inventory Quantity Store 500..., etc. Please keep in mind I have about 25,000 lines of informatin in my real files, so a macro approach is preferred.
    Could you point me in the right direction? I attached a file for better understanding. Thank you!
    Attached Files Attached Files

  2. #2
    Valued Forum Contributor
    Join Date
    06-16-2006
    Location
    Sydney, Australia
    MS-Off Ver
    2013 64bit
    Posts
    1,394

    Re: Cleaning up data

    Why do you want to do this? Unless you specifically are wanting to do this for data entry purposes for a legacy system, you would be better off putting your data in a table, and then use a pivot table to produce the output you describe.

    Ie, Create a table with the following headings
    Sku, description, size, location, quantity.

    Then insert a pivot table.

    Would that work?

  3. #3
    Registered User
    Join Date
    06-06-2011
    Location
    Houston, Texas
    MS-Off Ver
    Excel 2007
    Posts
    23

    Re: Cleaning up data

    Mallycat,
    I understand what you are saying, but it won't work. The primary reason is that the format which the data is in is not recognized by excel as being a list which can be imported into a pivot table.
    What I am specifically asking is how to get it into a table format. Perhaps I wasn't clear on that. The headings are not standard and the data falls into a unique format based on how many locations have the product. I am asking how to get my data into a standard format which I could later import into a pivot table.
    Thanks!
    Last edited by aldek; 04-23-2012 at 12:39 PM. Reason: Clarification

  4. #4
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,834

    Re: Cleaning up data

    Try
    
    Option Explicit
    
    Sub test()
    Dim a, i As Long, ii As Long, w(), n As Long, txt As String
    Dim AL As Object, e, s
    Set AL = CreateObject("System.Collections.ArrayList")
    n = 1
    a = Range("a1").CurrentRegion.Value
    txt = a(3, 4) & vbLf & a(2, 4)
    With CreateObject("Scripting.Dictionary")
        For i = 2 To UBound(a, 1) Step 2
            If a(i, 1) = "" Then Exit For
            If Not .exists(a(i, 1)) Then
                ReDim w(2)
                n = n + 1
                w(0) = n
                Set w(1) = _
                CreateObject("Scripting.Dictionary")
                w(2) = VBA.Array(a(i, 1), a(i, 2), a(i, 3))
                .Item(a(i, 1)) = w
            End If
            w = .Item(a(i, 1))
            For ii = 5 To UBound(a, 2)
                If a(i, ii) <> "" Then
                    If Not AL.contains(a(i, ii)) Then
                        AL.Add a(i, ii)
                    End If
                    w(1)(a(i, ii)) = w(1)(a(i, ii)) + a(i + 1, ii)
                End If
            Next
            .Item(a(i, 1)) = w
        Next
        AL.Sort
        ReDim a(1 To n + 1, 1 To AL.Count + 4)
        a(1, 1) = "SKU": a(1, 2) = "Item Description": a(1, 3) = "Size"
        For i = 0 To AL.Count - 1
            a(1, i + 4) = txt & AL(i)
        Next
        For Each e In .keys
            w = .Item(e)
            For i = 1 To 3
                a(w(0), i) = w(2)(i - 1)
            Next
            For Each s In w(1).keys
                For ii = 5 To UBound(a, 2)
                    a(w(0), AL.Indexof(s, 0) + 4) = w(1)(s)
                Next
            Next
        Next
    End With
    With Range("a1").CurrentRegion
        With .Offset(, .Columns.Count + 2)
            .CurrentRegion.Clear
            With .Resize(n, AL.Count + 3)
                .Value = a
                .ColumnWidth = 20
                .Columns.AutoFit
                .WrapText = True
                .Borders.Weight = 2
            End With
        End With
    End With
    Set AL = Nothing
    End Sub
    TestWithCode.xlsm

  5. #5
    Registered User
    Join Date
    06-06-2011
    Location
    Houston, Texas
    MS-Off Ver
    Excel 2007
    Posts
    23

    Re: Cleaning up data

    Jindon,
    This works very well for the first 9 items, but stumbles when it gets to "Coke". The store numbers should correspond to the lines beginning with "Quantity". So, for the example "Coke", store 0 should correspond to 0, store 1 to 3, store 2 to 0, store 3 to 6, etc. I know it's strange. Also, it stops right after the coke example. If I had more lines, perhaps 25,000, how would I get this to work?
    Thank you again! I appreciate your help!

  6. #6
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,834

    Re: Cleaning up data

    Then you need to show me the exact result from the sample data.

  7. #7
    Forum Expert nilem's Avatar
    Join Date
    10-22-2011
    Location
    Ufa, Russia
    MS-Off Ver
    2013
    Posts
    3,377

    Re: Cleaning up data

    as an option
    Sub ert()
    Dim x, y(), i&, j&, k&, n&, u&, id&, cnt&
    Application.ScreenUpdating = False
    x = Range("B3:R" & Cells(Rows.Count, 2).End(xlUp).Row + 1).Value
    For i = 1 To UBound(x)
        ReDim y(1 To 1000): u = i
        y(1) = x(i, 1): y(2) = x(i, 2): y(3) = x(i, 3)
    
        Do Until Not IsNumeric(x(i + 1, 4))
            i = i + 1
        Loop
        n = i - u + 1
        For k = u To i
            For j = 4 To UBound(x, 2)
                If IsNumeric(x(k, j)) Then
                    If Len(x(k, j)) Then id = x(k, j) + 4: y(id) = x(k + n, j)
                End If
            Next j
        Next k
        cnt = cnt + 1: Range("U3")(cnt, 1).Resize(, id).Value = y()
        i = i + n
    Next i
    Application.ScreenUpdating = True
    End Sub
    Attached Files Attached Files

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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