Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Excel / Programming / March 2008

Tip: Looking for answers? Try searching our database.

Rearranging data

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
John Pierce - 20 Mar 2008 04:52 GMT
I've been given some data that looks like this:
Name    Docs
Name1    doc1
Name1    doc3
Name2    doc2
Name2    doc3
Name3    doc1
Name4    doc1
Name4    doc2
Name4    doc3
Name5    doc1
Name5    doc3
Name6    doc3

and I need it to look like this:

Name    Doc1    Doc2    Doc3
Name1    X        X
Name2        X    X
Name3    X
Name4    X    X    X
Name5    X        X
Name6            X

There are thousands of records but only three different doc types.
For each Name, all three docs might be there, or only one, or
any combination of two of them.
OssieMac - 20 Mar 2008 08:39 GMT
Hi John,

try this.

Sub Rearrange()

Dim ws1 As Worksheet
Dim ws2 As Worksheet
Dim rngNames As Range
Dim colNames As String
Dim c As Range
Dim saveName As String
Dim offSetCol As Long

Set ws1 = Sheets("Sheet1")  'Edit with original list sheet name
Set ws2 = Sheets("Sheet2")  'Edit with your Output sheet name

colNames = "A"  'Edit to your column of names

With ws1
   Set rngNames = Range(.Cells(2, colNames), _
       .Cells(.Rows.Count, colNames).End(xlUp))
End With

With ws2
   .Cells(1, "A") = "Name"
   .Cells(1, "B") = "Doc1"
   .Cells(1, "C") = "Doc2"
   .Cells(1, "D") = "Doc3"
End With

For Each c In rngNames
   If c.Value <> saveName Then
       With ws2
           .Cells(.Rows.Count, "A").End(xlUp). _
               Offset(1, 0) = c.Value
           saveName = c.Value
       End With
   End If
   If c.Offset(0, 1) <> "" Then
       Select Case Right(c.Offset(0, 1), 1)
           Case 1
               offSetCol = 1
           Case 2
               offSetCol = 2
           Case 3
               offSetCol = 3
       End Select
       With ws2
           .Cells(.Rows.Count, "A").End(xlUp). _
           Offset(0, offSetCol) = "X"
       End With
   End If
Next c

End Sub

Signature

Regards,

OssieMac

> I've been given some data that looks like this:
> Name    Docs
[quoted text clipped - 23 lines]
> For each Name, all three docs might be there, or only one, or
> any combination of two of them.
John Pierce - 25 Mar 2008 13:59 GMT
> HiJohn,
>
[quoted text clipped - 88 lines]
>
> - Show quoted text -

OssieMac, Thank you. Your procedure works perfectly.
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.