Solved

transpose rows to column data

Posted on 2013-11-11
3
300 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

A little background as to how I came to I design this code: Around 5 years ago I designed an add-in that formatted Excel files to a corporate standard, applying different cell colours and font type depending on whether the cells contained inputs,…
Workbook link problems after copying tabs to a new workbook? David Miller (dlmille) Intro Have you either copied sheets to a new workbook, and after having saved and opened that workbook, you find that there are links back to the original sou…
The view will learn how to download and install SIMTOOLS and FORMLIST into Excel, how to use SIMTOOLS to generate a Monte Carlo simulation of 30 sales calls, and how to calculate the conditional probability based on the results of the Monte Carlo …
The viewer will learn how to create two correlated normally distributed random variables in Excel, use a normal distribution to simulate the return on different levels of investment in each of the two funds over a period of ten years, and, create a …

932 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now