How do I split one row into multiple rows with Excel?

GreysonD

I have a product database in Excel with several hundred entries, each of which has from 1 to 3 "tiers" of pricing: Standard, Deluxe, and Premium. Each tier has its own SKU (A, B, or C added on to the end of the base SKU) and price. My data is like this:

Name, Description, Price A, Price B, Price C, SKU A, SKU B, SKU C
name1,      desc1,   14.95,   19.95,        , sku1A, sku1B, 
name2,      desc2,    4.95,    9.95,   12.95, sku2A, sku2B, sku2C
name3,      desc3,   49.95,        ,        , sku3A,      ,

How would I go about getting the data to look like this:

Name, Description,   SKU, Price
name1,      desc1, sku1A, 14.95
name1,      desc1, sku1B, 19.95
name2,      desc2, sku2A,  4.95
name2,      desc2, sku2B,  9.95
name2,      desc2, sku2C, 12.95
name3,      desc3, sku3A, 49.95

If it helps, I'm going to be importing these products into a Magento installation.

Thank you in advanced.

nixda

Those tasks are usually faster with VBA. In fact, it took me ~10 minutes to set it up.
I'm assuming your data is in column A to column H.

Go to Excel » Developer » Visual Basic » On the left pane open sheet1 (or) the sheet where your data resides » Insert the code at the right window » Run the code

VBA code

1 |Sub NewLayout()
2 |    For i = 2 To Cells.Find("*", [A1], , , xlByRows, xlPrevious).Row
3 |        For j = 0 To 2
4 |        If Cells(i, 3 + j) <> vbNullString Then
5 |            intCount = intCount + 1
6 |            Cells(i, 1).Copy Destination:=Cells(intCount, 10)
7 |            Cells(i, 2).Copy Destination:=Cells(intCount, 11)
8 |            Cells(i, 3 + j).Copy Destination:=Cells(intCount, 12)
9 |            Cells(i, 6 + j).Copy Destination:=Cells(intCount, 13)
10|        End If
11|        Next j
12|    Next i
13|End Sub

Explanation

It was my intention to keep the code as short as possible to explain it better. Basically we use two loops. The outer loop (i) is for the rows and the inner loop (j) for the price columns.

We heavily use cells(rowNumber,columnNumber) to read/write cells.

  • Line 2| Start a loop from row 2 to your last row. We iterate through every used row

  • Line 3| Start a second loop from 0 to 2 (that are actually 3 loops, one for every Price column)

  • Line 4| We use this inner loop to check for values in our current row and column Price A, then Price B and in the last loop Price C. If we find a value in a Price column, we go on and copy cells. If no Price is inserted, we do nothing and go on to the next Price column

  • Line 5| Count up a counter to know how many rows we already copied,
    so we know after what row we can copy our current row

  • Line 6| Copy the name column

  • Line 7| Copy the description column

  • Line 8| Copy the Price A or B or C column depending on what inner loop we currently are

  • Line 9| Copy the SKU A or B or C column depending on what inner loop we currently are

Result screenshot

enter image description here

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Split one row into multiple rows in excel

From Dev

How do i split a single row of columns into multiple rows and columns?

From Dev

Split one row into multiple rows

From Dev

How do I split a single row into multiple rows and Insert into a table in Oracle?

From Dev

Postgres, split one row into multiple rows with conditions

From Dev

Pandas: How do I split multiple lists in columns into multiple rows?

From Dev

How do I normalize/flatten an Excel row with multiple values into single rows with single values?

From Dev

Using SQL SMS, how do I combine multiple rows into one row, but maintain all the column data?

From Dev

How do I split multiple columns into rows by delimiter in Power BI?

From Dev

how do i split multiple rows in different column in pandas

From Dev

Excel Data Manipulation - One Row into Multiple Rows

From Dev

How to split a single row into multiple rows in SQL

From Dev

How to split a row in multiple rows SQL Server?

From Dev

How do I create two rows from one row SQL

From Dev

How do I add one row of a PANDAS dataframe to the rest of the rows?

From Dev

How do I flatMap a row of arrays into multiple rows?

From Dev

How do I convert multiple rows into a single row

From Dev

how do I split from one variable into multiple variables in javascript?

From Dev

How to split one variable into multiple rows

From Dev

How to split a single row into multiple rows, each with their own cell values for the differing columns in Excel table

From Dev

How do I move the selection down one row in Excel 2007?

From Dev

sql split one row to multiple rows based on number of columns available

From Dev

How do I get one column with one row and one column with two rows nested in HTML/CSS

From Dev

How do you select multiple rows in one table, but only one row in another?

From Dev

How can I move data from multiple columns and multiple rows to 1 single row in excel

From Dev

how do i group rows by an id row in group_concat into one row string?

From Dev

Excel: how to create multiple rows from one

From Dev

How to split 4 columns, one row into 2 columns, two rows?

From Dev

How do I fadeIn rows one by one?

Related Related

  1. 1

    Split one row into multiple rows in excel

  2. 2

    How do i split a single row of columns into multiple rows and columns?

  3. 3

    Split one row into multiple rows

  4. 4

    How do I split a single row into multiple rows and Insert into a table in Oracle?

  5. 5

    Postgres, split one row into multiple rows with conditions

  6. 6

    Pandas: How do I split multiple lists in columns into multiple rows?

  7. 7

    How do I normalize/flatten an Excel row with multiple values into single rows with single values?

  8. 8

    Using SQL SMS, how do I combine multiple rows into one row, but maintain all the column data?

  9. 9

    How do I split multiple columns into rows by delimiter in Power BI?

  10. 10

    how do i split multiple rows in different column in pandas

  11. 11

    Excel Data Manipulation - One Row into Multiple Rows

  12. 12

    How to split a single row into multiple rows in SQL

  13. 13

    How to split a row in multiple rows SQL Server?

  14. 14

    How do I create two rows from one row SQL

  15. 15

    How do I add one row of a PANDAS dataframe to the rest of the rows?

  16. 16

    How do I flatMap a row of arrays into multiple rows?

  17. 17

    How do I convert multiple rows into a single row

  18. 18

    how do I split from one variable into multiple variables in javascript?

  19. 19

    How to split one variable into multiple rows

  20. 20

    How to split a single row into multiple rows, each with their own cell values for the differing columns in Excel table

  21. 21

    How do I move the selection down one row in Excel 2007?

  22. 22

    sql split one row to multiple rows based on number of columns available

  23. 23

    How do I get one column with one row and one column with two rows nested in HTML/CSS

  24. 24

    How do you select multiple rows in one table, but only one row in another?

  25. 25

    How can I move data from multiple columns and multiple rows to 1 single row in excel

  26. 26

    how do i group rows by an id row in group_concat into one row string?

  27. 27

    Excel: how to create multiple rows from one

  28. 28

    How to split 4 columns, one row into 2 columns, two rows?

  29. 29

    How do I fadeIn rows one by one?

HotTag

Archive