Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

transpose rows to column data

Posted on 2013-11-11
3
Medium Priority
?
339 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 40

Accepted Solution

by:
als315 earned 2000 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

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

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

Microsoft's Excel has many features that most people will never need nor take advantage of.  Conditional formatting is one feature that you may find a necessity once you start using it.
Windows Explorer let you handle zip folders nearly as any other folder: Copy, move, change, and delete, etc. In VBA you can also handle normal files and folders, but zip folders takes a little more - and that you'll find here.
This Micro Tutorial will demonstrate how to create pivot charts out of a data set. I also added a drop-down menu which allows to choose from different categories in the data set and the chart will automatically update.
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

876 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