+ Reply to Thread
Results 1 to 5 of 5

Need help with macro to clean up a table of data

Hybrid View

FSUMBA97 Need help with macro to clean... 03-08-2013, 01:29 PM
arlu1201 Re: Need help with macro to... 03-08-2013, 01:43 PM
FSUMBA97 Re: Need help with macro to... 03-08-2013, 02:09 PM
mike7952 Re: Need help with macro to... 03-08-2013, 05:35 PM
FSUMBA97 Re: Need help with macro to... 03-11-2013, 10:37 AM
  1. #1
    Registered User
    Join Date
    03-21-2011
    Location
    Atlanta, GA
    MS-Off Ver
    Excel 2010
    Posts
    24

    Need help with macro to clean up a table of data

    You guys have been VERY helpful on things like this before. Need your help again, please!

    This is an Excel data dump out of SAGE. Tab1 is how it it comes. Tab 2 is how I am trying to reorg it. In column A, the first number is the SKU, then the following numbers in A are the Location, then a space, then a new item same set-up. I need location broke out into the 2nd column and the SKU in the 1st column and the remaining information following to the right. When the space appears in column A the totals to the right are sums and I do not need the at all.

    There are approx 250,000 lines of data in this table so doing by hand will get ugly.

  2. #2
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,166

    Re: Need help with macro to clean up a table of data

    I have seen a max of 2 LOC codes for each SKU. Are there chances of more?
    If I have helped, Don't forget to add to my reputation (click on the star below the post)
    Don't forget to mark threads as "Solved" (Thread Tools->Mark thread as Solved)
    Use code tags when posting your VBA code: [code] Your code here [/code]

  3. #3
    Registered User
    Join Date
    03-21-2011
    Location
    Atlanta, GA
    MS-Off Ver
    Excel 2010
    Posts
    24

    Re: Need help with macro to clean up a table of data

    Actually, I have seen 4 and 5 locations on a single SKU.

  4. #4
    Forum Expert mike7952's Avatar
    Join Date
    12-17-2011
    Location
    Florida
    MS-Off Ver
    Excel 2007, Excel 2016
    Posts
    3,551

    Re: Need help with macro to clean up a table of data

    Give this a try

    Option Explicit
    
    Sub abc()
     Dim aArrClean() As Variant
     Dim a, i As Long, n As Long, sSku As String, sDesc As String, sAct As String
     
     With Worksheets("Copy of Sage Valuation Report a")
        a = .Range("a3", .Cells(Rows.Count, "a").End(xlUp).Offset(, 6))
     End With
     ReDim aArrClean(1 To UBound(a), 1 To 7)
     
     For i = 1 To UBound(a)
        If IsEmpty(a(i, 1)) And IsEmpty(a(i, 2)) Then
            'Do nothing
        Else
            If Not IsEmpty(a(i, 1)) And Not IsEmpty(a(i, 2)) Then
                sSku = a(i, 1)
                sDesc = a(i, 2)
                sAct = a(i, 3)
            Else
                n = n + 1
                aArrClean(n, 1) = sSku
                aArrClean(n, 2) = a(i, 1)
                aArrClean(n, 3) = sDesc
                aArrClean(n, 4) = sAct
                aArrClean(n, 5) = a(i, 4)
                aArrClean(n, 6) = a(i, 5)
                aArrClean(n, 7) = a(i, 6)
            End If
            
        End If
     Next
     Worksheets.Add
     With Cells(1).Resize(, 7)
        .Font.Bold = True
        .Value = Array("SKU", "LOC", "Description", "Active", "Cost", "Qty", "Value")
     End With
     Cells(2, 1).Resize(n, 7) = aArrClean
     Columns.AutoFit
    End Sub
    Thanks,
    Mike

    If you are satisfied with the solution(s) provided, please mark your thread as Solved.
    Select Thread Tools-> Mark thread as Solved.

  5. #5
    Registered User
    Join Date
    03-21-2011
    Location
    Atlanta, GA
    MS-Off Ver
    Excel 2010
    Posts
    24

    Re: Need help with macro to clean up a table of data

    Mike,
    That worked great! Thanks!

+ 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