Solved

transpose rows to column data

Posted on 2013-11-11
3
308 Views
Last Modified: 2013-11-11
excel 2010 vba

I have a list in Excel
That if the Number in column A is repeated. then its gets transposed to as many colmns as it needs depending on how many rows exist on the number in column A.

I have attached an example sheet with some data already transposed.

Thanks
fordraiders
The code belowe does not work



Looks like this
3755	BONNET	Abrasives
3755	BONNET	HVAC and Refrigeration
3755	BONNET	Plumbing
3755	BONNET	Cleaning
3755	BONNET	Plumbing
3756	BOOK	Reference and Learning Supplies
3756	BOOK	Reference and Learning Supplies
3757	BOOM	Material Handling
3757	BOOM	Pneumatics
3758	BOOM	Material Handling
3758	BOOM	Pneumatics
  


end up like this

A                  B                                          C                            D           E          F
3755	BONNET	Abrasives	                         HVAC and Refrigeration          plumbing     Cleaning  Plumbing
3756	BOOK	Reference and Learning Supplies          Reference and Learning Supplies
3757	BOOM	Material Handling	                 Pneumatics
3758	BOOM	Material Handling	                 Pneumatics

Open in new window



Sub ColsToRows()
  Dim cRow As Long      'Row we're cutting from
  Dim pRow As Long      'Row we're pasting to
  Dim codeCol As String 'Column containing list of names
 
  codeCol = "A"
  cRow = 10
  pRow = 2
 
  Do While Range(codeCol & cRow).Value <> ""
    If Range(codeCol & cRow).Value = Range(codeCol & pRow).Value Then
      Range(codeCol & pRow).End(xlToRight).Offset(0, 1).Value = Range(codeCol & cRow).Offset(0, 1)
      Range(codeCol & cRow).EntireRow.ClearContents
    Else
      pRow = pRow + 1
      If pRow = cRow Then Exit Do
      Range(Range(codeCol & cRow).Address, Range(codeCol & cRow).Offset(0, 1).Address).Copy Destination:=Range(codeCol & pRow)
      Range(codeCol & cRow).EntireRow.ClearContents
    End If
    cRow = cRow + 1
  Loop
End Sub

Open in new window

0
Comment
Question by:fordraiders
  • 2
3 Comments
 
LVL 39

Accepted Solution

by:
als315 earned 500 total points
ID: 39640761
Look at sample. Sub is in Module1
Transpose.xlsm
0
 
LVL 3

Author Comment

by:fordraiders
ID: 39640776
getting type mismatch on this line

Code = inWs.Cells(inRow, codeCol).Value   <----------------

I have attached my file...
2dp-Request.xlsm
0
 
LVL 3

Author Closing Comment

by:fordraiders
ID: 39640848
took out column headers  and some blank rows.
worked fine.
0

Featured Post

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Drop Down List with Unique/Distinct Values (Part II - ComboBox or ListBox and Data Validation List Bonus!) David Miller (dlmille) Intro This article focuses on delivering unique, sorted lists to list objects (e.g., ComboBox, ListBox) and Dat…
This article will guide you to convert a grid from a picture into Excel format using Microsoft OneNote and no other 3rd party application.
This Micro Tutorial will demonstrate in Microsoft Excel how to add style and sexy appeal to horizontal bar charts.
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

808 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question