1

How do I take one row of data in Excel and split it into multiple rows?

Given this input:

Name      Award Type 1     Amount 1     Award Type 2    Amount 2
Dan       Top Performer    $5,000       Top Region      $10,000 
Kathy     Rep Planmaker    $2,500

I want to convert it to this:

Name      Award Type       Amount
Dan       Top Performer    $5,000
Dan       Top Region       $10,000
Kathy     Rep Planmaker    $2,500

In words: since the “Dan” row in the input data shows two awards – one in columns B&C and another in columns D&E – I want to split Dan’s data into two rows, one for each award.

3

1 Answer 1

1
Sub convert()
    Dim intcount As Integer
    intcount = 1
    For i = 2 To **123**
        For j = 0 To 1
            If ThisWorkbook.Sheets("sheet1").Cells(i, 1 + 2 * j).Value <> vbNullString Then
                intcount = intcount + 1
                ThisWorkbook.Sheets("sheet1").Cells(i, 1).Copy Destination:=ThisWorkbook.Sheets("sheet2").Cells(intcount, 1)
                ThisWorkbook.Sheets("sheet1").Cells(i, 2 + 2 * j).Copy Destination:=ThisWorkbook.Sheets("sheet2").Cells(intcount, 2)
                ThisWorkbook.Sheets("sheet1").Cells(i, 3 + 2 * j).Copy Destination:=ThisWorkbook.Sheets("sheet2").Cells(intcount, 3)
            End If
        Next
    Next
End Sub

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .