+ Reply to Thread
Results 1 to 4 of 4

Rearranging Data

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    10-27-2005
    Posts
    177

    Rearranging Data

    Hi everyone

    Please see attached.

    In the Initial sheet, I have data where column A lists products and columns B onwards lists serial numbers for those products.

    So, Widget A (cell A1) has serial numbers listed in B1 to D1
    Widget B (cell A4) has serial numbers listed in B4 to H4
    And vice versa

    I would like to order the data such that the serial numbers are listed in one column (col B) and in column A it lists the product. The desired result is in the Result sheet.

    Is there a way to do this via macro? Any assistance would be very much appreciated.
    Attached Files Attached Files
    Last edited by uberathlete; 09-06-2014 at 12:07 PM.

  2. #2
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Rearranging Data

    Here's a published macro that pretty much does exactly that:

    'ROWS TO COLUMNS
    Here's a macro for expanding rows of data to multiple rows parsing out the values in the row while duplicating the header row as categories. There's a sample workbook too you could drop your data into and test it out.
    Last edited by JBeaucaire; 12-26-2019 at 05:19 PM.
    _________________
    Microsoft MVP 2010 - Excel
    Visit: Jerry Beaucaire's Excel Files & Macros

    If you've been given good help, use the icon below to give reputation feedback, it is appreciated.
    Always put your code between code tags. [CODE] your code here [/CODE]

    ?None of us is as good as all of us? - Ray Kroc
    ?Actually, I *am* a rocket scientist.? - JB (little ones count!)

  3. #3
    Valued Forum Contributor
    Join Date
    03-21-2013
    Location
    cyberia
    MS-Off Ver
    Excel 2007
    Posts
    457

    Re: Rearranging Data

    Quote Originally Posted by uberathlete View Post
    Any assistance would be very much appreciated.
    here's a bit more
    Sub two_cols()
    Dim a, u(), c As Long, i As Long, j As Long
    a = Cells(1).CurrentRegion
    ReDim u(1 To UBound(a, 1) * UBound(a, 2), 1 To 2)
    For i = 1 To UBound(a, 1)
        For j = 2 To UBound(a, 2)
            If Len(a(i, j)) > 0 Then
                c = c + 1
                u(c, 1) = a(i, 1)
                u(c, 2) = a(i, j)
            End If
        Next j
    Next i
    Cells(UBound(a, 1) + 2, 1).Resize(c, 2) = u
    End Sub

  4. #4
    Forum Contributor
    Join Date
    10-27-2005
    Posts
    177

    Re: Rearranging Data

    Thank you so much JBeaucaire and kalak! These are exactly what I was hoping for.

+ 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] rearranging data using VBA
    By longhorn23 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 08-20-2013, 05:21 PM
  2. rearranging data
    By kbka in forum Excel General
    Replies: 6
    Last Post: 10-11-2011, 04:55 PM
  3. Rearranging data
    By Lenie in forum Excel General
    Replies: 5
    Last Post: 10-28-2010, 07:45 AM
  4. need: Rearranging data
    By Knawl in forum Excel General
    Replies: 20
    Last Post: 06-12-2009, 04:06 AM
  5. Need help on rearranging data
    By psatkar in forum Excel Formulas & Functions
    Replies: 7
    Last Post: 11-05-2006, 02:15 PM

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