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

Format cells as date
Select range and press Ctrl+Shift+3 to format cells as date. (Shift 3 is the # sign which sort of looks like a small calendar).

Andrew Poulsom

MrExcel MVP
Joined
Jul 21, 2002
Messages
73,092
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
 

depks

Board Regular
Joined
Sep 14, 2004
Messages
82
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
 

Forum statistics

Threads
1,136,263
Messages
5,674,710
Members
419,521
Latest member
Jasonnie

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
Top