+ Reply to Thread
Results 1 to 8 of 8

Convert horizontal values to match vertical ones in a table

Hybrid View

  1. #1
    Registered User
    Join Date
    01-31-2019
    Location
    Latvia
    MS-Off Ver
    2016
    Posts
    3

    Question Convert horizontal values to match vertical ones in a table

    Hello everyone, I'm trying to figure out a way to readjust my table, so that the columns with my size values would shift to match their vertical Color and Article counterparts. In summery, what I want to do is to divide my data, so that every Article+Color+Size+Quantity combination would have their own unique line, because i need to generate a unique barcode for each article+color+size combination. Any help appreciated.
    excel.png
    Last edited by dr4nce; 01-31-2019 at 10:34 AM.

  2. #2
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (both in England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2504 (Windows 11 Home 24H2 64-bit)
    Posts
    90,665

    Re: Convert horizontal values to match vertical ones in a table

    Welcome to the forum!

    You have marked this thread as solved - is it?
    Ali


    Enthusiastic self-taught user of MS Excel who's always learning!
    Don't forget to say "thank you" in your thread to anyone who has offered you help. It's a universal courtesy.
    You can reward them by clicking on * Add Reputation below their user name on the left, if you wish.

    NB:
    as a Moderator, I never accept friendship requests.
    Forum Rules (updated August 2023): please read them here.

  3. #3
    Registered User
    Join Date
    01-31-2019
    Location
    Latvia
    MS-Off Ver
    2016
    Posts
    3

    Re: Convert horizontal values to match vertical ones in a table

    Sorry, no that happened by mistake i fugure

  4. #4
    Forum Expert
    Join Date
    10-15-2018
    Location
    MA, USA
    MS-Off Ver
    2010, 2019
    Posts
    1,616

    Re: Convert horizontal values to match vertical ones in a table

    Here is a VBA solution.
    I assume:
    1) Your original data is on a worksheet named "Source"
    2) Your data starts at cell A1
    3) A blank worksheet named "Dest" exists and is where your re-arranged data will be written to.

    To do the data conversion:
    1) Clear contents on the "Dest" worksheet
    2) Populate the "Source" worksheet with your stock data.
    3) Run the "reorg_data" macro.
    4) The "Dest" worksheet will be populated with the reorganized data.

    Note that I have propagated the "Article" number onto each row of the "Dest" worksheet contrary to your example. This will really help later if you need to perform further analysis of the data. If you really need blanks in the "Article" column then the macro can easily be changed to do that.

    See the attached workbook.

    Here's the VBA:
    'Re-arrange stock data
    Option Explicit
    Dim rng As Range, rngO As Range
    Dim sourceRowNum As Integer, sourceColNum As Integer, destRowNum As Integer
    
    Sub reorg_data()
        With Worksheets("Source")
            Set rng = .UsedRange
            destRowNum = 2
            Set rngO = Worksheets("Dest").Range("A1")
            rngO.Cells(1, 1) = "Article"
            rngO.Cells(1, 2) = "Color"
            rngO.Cells(1, 3) = "Size"
            rngO.Cells(1, 4) = "Quantity"
            For sourceRowNum = 2 To rng.Rows.Count
                'Article
                rngO.Cells(destRowNum + 0, 1) = .Cells(sourceRowNum, 1)
                rngO.Cells(destRowNum + 1, 1) = .Cells(sourceRowNum, 1)
                rngO.Cells(destRowNum + 2, 1) = .Cells(sourceRowNum, 1)
                rngO.Cells(destRowNum + 3, 1) = .Cells(sourceRowNum, 1)
                'Color
                rngO.Cells(destRowNum + 0, 2) = .Cells(sourceRowNum, 2)
                rngO.Cells(destRowNum + 1, 2) = .Cells(sourceRowNum, 2)
                rngO.Cells(destRowNum + 2, 2) = .Cells(sourceRowNum, 2)
                rngO.Cells(destRowNum + 3, 2) = .Cells(sourceRowNum, 2)
                ' S, M, L, XL
                rngO.Cells(destRowNum + 0, 3) = .Cells(1, 3)
                rngO.Cells(destRowNum + 1, 3) = .Cells(1, 4)
                rngO.Cells(destRowNum + 2, 3) = .Cells(1, 5)
                rngO.Cells(destRowNum + 3, 3) = .Cells(1, 6)
                ' Quantities
                rngO.Cells(destRowNum + 0, 4) = .Cells(sourceRowNum - 0, 3)
                rngO.Cells(destRowNum + 1, 4) = .Cells(sourceRowNum - 0, 4)
                rngO.Cells(destRowNum + 2, 4) = .Cells(sourceRowNum - 0, 5)
                rngO.Cells(destRowNum + 3, 4) = .Cells(sourceRowNum - 0, 6)
                destRowNum = destRowNum + 4
            Next sourceRowNum
        End With
    End Sub
    Attached Files Attached Files
    Last edited by GeoffW283; 01-31-2019 at 09:37 PM.

  5. #5
    Forum Guru Pete_UK's Avatar
    Join Date
    12-31-2011
    Location
    Warrington, England
    MS-Off Ver
    Office 2019 (still learning)
    Posts
    25,417

    Re: Convert horizontal values to match vertical ones in a table

    You could also do it with a few formulae, but it's getting a bit too late for me to work on it now.

    Pete

  6. #6
    Registered User
    Join Date
    01-31-2019
    Location
    Latvia
    MS-Off Ver
    2016
    Posts
    3

    Re: Convert horizontal values to match vertical ones in a table

    Quote Originally Posted by GeoffW283 View Post
    Here is a VBA solution.
    I assume:
    1) Your original data is on a worksheet named "Source"
    2) Your data starts at cell A1
    3) A blank worksheet named "Dest" exists and is where your re-arranged data will be written to.

    To do the data conversion:
    1) Clear contents on the "Dest" worksheet
    2) Populate the "Source" worksheet with your stock data.
    3) Run the "reorg_data" macro.
    4) The "Dest" worksheet will be populated with the reorganized data.

    Note that I have propagated the "Article" number onto each row of the "Dest" worksheet contrary to your example. This will really help later if you need to perform further analysis of the data. If you really need blanks in the "Article" column then the macro can easily be changed to do that.

    See the attached workbook.

    Here's the VBA:
    'Re-arrange stock data
    Option Explicit
    Dim rng As Range, rngO As Range
    Dim sourceRowNum As Integer, sourceColNum As Integer, destRowNum As Integer
    
    Sub reorg_data()
        With Worksheets("Source")
            Set rng = .UsedRange
            destRowNum = 2
            Set rngO = Worksheets("Dest").Range("A1")
            rngO.Cells(1, 1) = "Article"
            rngO.Cells(1, 2) = "Color"
            rngO.Cells(1, 3) = "Size"
            rngO.Cells(1, 4) = "Quantity"
            For sourceRowNum = 2 To rng.Rows.Count
                'Article
                rngO.Cells(destRowNum + 0, 1) = .Cells(sourceRowNum, 1)
                rngO.Cells(destRowNum + 1, 1) = .Cells(sourceRowNum, 1)
                rngO.Cells(destRowNum + 2, 1) = .Cells(sourceRowNum, 1)
                rngO.Cells(destRowNum + 3, 1) = .Cells(sourceRowNum, 1)
                'Color
                rngO.Cells(destRowNum + 0, 2) = .Cells(sourceRowNum, 2)
                rngO.Cells(destRowNum + 1, 2) = .Cells(sourceRowNum, 2)
                rngO.Cells(destRowNum + 2, 2) = .Cells(sourceRowNum, 2)
                rngO.Cells(destRowNum + 3, 2) = .Cells(sourceRowNum, 2)
                ' S, M, L, XL
                rngO.Cells(destRowNum + 0, 3) = .Cells(1, 3)
                rngO.Cells(destRowNum + 1, 3) = .Cells(1, 4)
                rngO.Cells(destRowNum + 2, 3) = .Cells(1, 5)
                rngO.Cells(destRowNum + 3, 3) = .Cells(1, 6)
                ' Quantities
                rngO.Cells(destRowNum + 0, 4) = .Cells(sourceRowNum - 0, 3)
                rngO.Cells(destRowNum + 1, 4) = .Cells(sourceRowNum - 0, 4)
                rngO.Cells(destRowNum + 2, 4) = .Cells(sourceRowNum - 0, 5)
                rngO.Cells(destRowNum + 3, 4) = .Cells(sourceRowNum - 0, 6)
                destRowNum = destRowNum + 4
            Next sourceRowNum
        End With
    End Sub
    Oh my god Geoff, you're a lifesaver! Thank you so much!

  7. #7
    Forum Expert
    Join Date
    10-15-2018
    Location
    MA, USA
    MS-Off Ver
    2010, 2019
    Posts
    1,616

    Re: Convert horizontal values to match vertical ones in a table

    No problem, glad to help. Thanks for the feedback and reputation points!

  8. #8
    Forum Expert
    Join Date
    12-09-2014
    Location
    Trakai, Lithuania
    MS-Off Ver
    2016
    Posts
    1,416

    Re: Convert horizontal values to match vertical ones in a table

    See the application for formulas.
    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)

Similar Threads

  1. [SOLVED] SUM of values using horizontal and vertical criteria of a Table
    By d_whys in forum Excel Formulas & Functions
    Replies: 6
    Last Post: 10-15-2018, 06:37 PM
  2. Match vertical and horizontal values and return value
    By Nick2512 in forum Excel Formulas & Functions
    Replies: 7
    Last Post: 02-28-2018, 10:46 AM
  3. Replies: 16
    Last Post: 06-01-2017, 06:01 PM
  4. Replies: 3
    Last Post: 09-25-2014, 02:14 PM
  5. [SOLVED] Convert horizontal data to vertical for Pivot table
    By jonpaulson in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 01-10-2014, 12:47 PM
  6. [SOLVED] Convert Horizontal Table to Vertical List
    By TXboiler in forum Excel General
    Replies: 3
    Last Post: 04-22-2011, 09:27 PM

Tags for this Thread

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