Solved

transpose rows to column data

Posted on 2013-11-11
3
290 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
Comment Utility
Look at sample. Sub is in Module1
Transpose.xlsm
0
 
LVL 3

Author Comment

by:fordraiders
Comment Utility
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
Comment Utility
took out column headers  and some blank rows.
worked fine.
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Sparklines have been introduced with Excel 2010 and are a useful tool for creating small in-cell charts, used for example in dashboards. Excel 2010 offers three different types of Sparklines: Line, Column and Win/Loss. What it does not offer is a…
How to quickly and accurately populate Word documents with Excel data, charts and images (including Automated Bookmark generation) David Miller (dlmille) Synopsis In this article you’ll learn how to use ExcelToWord! to copy data,charts, shapes …
The viewer will learn how to simulate a series of sales calls dependent on a single skill level and learn how to simulate a series of sales calls dependent on two skill levels. Simulating Independent Sales Calls: Enter .75 into cell C2 – “skill leve…
The viewer will learn how to use the =DISCRINV command to create a discrete random variable, use this command to model a set of probabilities and outcomes in a Monte Carlo simulation, and learn how to find the standard deviation of a set of probabil…

744 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

21 Experts available now in Live!

Get 1:1 Help Now