+ Reply to Thread
Results 1 to 4 of 4

Automatically reorganizing 1 row into multiple columns

  1. #1
    Registered User
    Join Date
    03-31-2023
    Location
    Nederland
    MS-Off Ver
    2017
    Posts
    2

    Post Automatically reorganizing 1 row into multiple columns

    Hello,

    The last few days i've been trying to import a database from excel into our SQL-database. I however ran into a problem.
    Background info: i built a C# app to solve a problem within our company, which has previously been solved within an Excel-sheet and database within that Excel-file. To import the Excel-database into our SQL-database, i have to re-organize 325 rows with anywhere from 4 through 12 columns into rows of 4 columns. In this case: per ColorID, KCNumber, Color and Quantity 1 row so i can call the data with a query within my C#-app.

    In the sprits of 'One picture means more than a thousand words', hereby a snapshot of the database. On the left the status quo, on the right the desired situation. The total should come out to 1000+ rows, so manually adjusting things is not an option ;)
    EXAMPLE.xlsx

    Does anyone have a bright idea on how to approach this challenge? I've been contemplating about building a custom app which reads the database per cell, and then manually inserting them into my SQL-database but this seems like overkill.

    Thanks in advance!
    Last edited by GijsPraat; 03-31-2023 at 05:34 AM.

  2. #2
    Forum Expert bebo021999's Avatar
    Join Date
    07-22-2011
    Location
    Vietnam
    MS-Off Ver
    Excel 2016
    Posts
    9,466

    Re: Automatically reorganizing 1 row into multiple columns

    May be:
    PHP Code: 
    Option Explicit
    Sub test
    ()
    Dim lr&, i&, j&, k&, rngres(1 To 1000001 To 4)
    lr Cells(Rows.Count"B").End(xlUp).Row ' last used row in column B
    rng = Range("B3:O" & lr).Value ' 
    read value into array "rng"
    For 1 To UBound(rng' row loop
        For j = 3 To UBound(rng, 2) '
    column loop from column D  to O
            
    If rng(ij) <> "" Then 'if cell is not empty
                If WorksheetFunction.IsOdd(j) Then ' 
    if column index =1,3,(color column)
                    
    ' result row+ 1
                    res(k, 1) = rng(i, 1): res(k, 2) = rng(i, 2): res(k, 3) = rng(i, j): res(k, 4) = rng(i, j + 1)
                End If
            End If
        Next
    Next
    Range("Q3:T10000").ClearContents
    Range("Q3").Resize(k, 4).Value = res
    End Sub 
    Attached Files Attached Files
    Quang PT

  3. #3
    Registered User
    Join Date
    03-31-2023
    Location
    Nederland
    MS-Off Ver
    2017
    Posts
    2

    Re: Automatically reorganizing 1 row into multiple columns

    Thanks for your quick answer - it worked like a charm! You're the best, thanks!

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

    Re: Automatically reorganizing 1 row into multiple columns

    Power Query
    Please Login or Register  to view this content.
    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. Replies: 1
    Last Post: 11-14-2017, 11:06 PM
  2. [SOLVED] Reorganizing data from columns with headers to a different column and row format
    By telcocook in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 10-27-2015, 02:24 PM
  3. Reorganizing data into blank cells a variable number of columns to the right
    By zookeepertx in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 10-15-2014, 04:45 PM
  4. Replies: 17
    Last Post: 02-11-2014, 10:00 AM
  5. [SOLVED] Reorganizing data from multiple sheets onto a master
    By Rascal50 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 07-29-2012, 02:54 PM
  6. How to sum multiple columns automatically
    By BBoydAnchor in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 12-27-2011, 10:20 AM
  7. Reorganizing Data in Excel from Rows to Columns
    By [email protected] in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 04-10-2006, 12:00 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