Re-arranging data

depks

Board Regular
Joined
Sep 14, 2004
Messages
82
Consider the following data in Excel
AutoCAD VB VC++ .NET
PC01 Yes Yes
PC02 Yes
PC03 Yes Yes

I want to re-arrange the data in the following format.
PC number Software1 Software2 re 3
PC01 AutoCAD VC++
PC02 VB
PC03 AutoCAD .NET

Thank you in advance.[/img]
 

Excel Facts

How can you turn a range sideways?
Copy the range. Select a blank cell. Right-click, Paste Special, then choose Transpose.
Try:

Code:
Sub Test()
    Dim Sh As Worksheet
    Dim Rng As Range
    Dim ShNew As Worksheet
    Dim r As Long
    Dim c As Integer
    Dim Col As Long
    Set Sh = Worksheets("Sheet1")
    Set Rng = Sh.Range("A1").CurrentRegion
    Set ShNew = Worksheets.Add
    ShNew.Cells(1, 1).Value = "PC number"
    For c = 2 To Rng.Columns.Count
        ShNew.Cells(1, c).Value = "Software" & c - 1
    Next c
    Col = 2
    For r = 2 To Rng.Rows.Count
        ShNew.Cells(r, 1).Value = Rng.Cells(r, 1).Value
        For c = 2 To Rng.Columns.Count
            If Rng.Cells(r, c).Value = "Yes" Then
                ShNew.Cells(r, Col).Value = Rng.Cells(1, c).Value
                Col = Col + 1
            End If
        Next c
        Col = 2
    Next r
End Sub
 
Upvote 0
Thanks a lot Mr.Andrew Poulsom. It worked!

Try:

Code:
Sub Test()
    Dim Sh As Worksheet
    Dim Rng As Range
    Dim ShNew As Worksheet
    Dim r As Long
    Dim c As Integer
    Dim Col As Long
    Set Sh = Worksheets("Sheet1")
    Set Rng = Sh.Range("A1").CurrentRegion
    Set ShNew = Worksheets.Add
    ShNew.Cells(1, 1).Value = "PC number"
    For c = 2 To Rng.Columns.Count
        ShNew.Cells(1, c).Value = "Software" & c - 1
    Next c
    Col = 2
    For r = 2 To Rng.Rows.Count
        ShNew.Cells(r, 1).Value = Rng.Cells(r, 1).Value
        For c = 2 To Rng.Columns.Count
            If Rng.Cells(r, c).Value = "Yes" Then
                ShNew.Cells(r, Col).Value = Rng.Cells(1, c).Value
                Col = Col + 1
            End If
        Next c
        Col = 2
    Next r
End Sub
 
Upvote 0

Forum statistics

Threads
1,215,059
Messages
6,122,917
Members
449,093
Latest member
dbomb1414

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top