Wrox Programmer Forums
|
Excel VBA Discuss using VBA for Excel programming.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Excel VBA section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old March 5th, 2005, 05:57 PM
Registered User
 
Join Date: Mar 2005
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Default transfer and transpose

Hi, I've got a problem.
I was given a data which look like this:(it's a dummy data)

KLM 130205 1.30
KLM 140205 1.29
SDF 130205 0.90
SDF 140205 1.20
SDF 150205 1.29
FGH 130205 2.50
FGH 140205 2.30

and so on.. there will always be 3letter word for the company name. The 2nd column is the date and the 3rd is the share price.

Now, I need a macro to do this:

KLM 130205 1.30 SDF 130205 0.90 FGH 130205 2.50
KLM 140205 1.29 SDF 140205 1.20 FGH 140205 2.30
                          SDF 150205 1.29

Please could anyone help me with this? I'm stuck!
Thanks in advance.
 
Old March 6th, 2005, 04:07 AM
Friend of Wrox
 
Join Date: Oct 2003
Posts: 168
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi

Try this one

Sub Transpose()
Dim Col As Byte
Dim RowNr As Long, l As Long
Col = 5
'Change l = 2 if you want to start in row 2...
l = 1
Do Until IsEmpty(Cells(l, 1))
    RowNr = 1
    Do
        Cells(RowNr, Col) = Cells(l, 1)
        Cells(RowNr, Col + 1) = Cells(l, 2)
        Cells(RowNr, Col + 2) = Cells(l, 3)
        RowNr = RowNr + 1
        l = l + 1
    Loop While Cells(l, 1) = Cells(l - 1, 1)
    Col = Col + 3
Loop
End Sub

-vemaju

 
Old March 6th, 2005, 08:53 AM
Registered User
 
Join Date: Mar 2005
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Default

hi, it works great!
But I want to copy it to another workbook, can you tell me how?
thanks in advance

 
Old March 6th, 2005, 10:43 AM
Friend of Wrox
 
Join Date: Oct 2003
Posts: 168
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi
This one creates a new workbook and transposes table to new one

Sub Transpose()
Dim Col As Byte
Dim RowNr As Long, l As Long
Dim Book As Object
Workbooks.Add
Set Book = ActiveWorkbook.Sheets(1)
ThisWorkbook.Activate
Col = 1
l = 1
Do Until IsEmpty(Cells(l, 1))
    RowNr = 1
    Do
        Book.Cells(RowNr, Col) = Cells(l, 1)
        Book.Cells(RowNr, Col + 1) = Cells(l, 2)
        Book.Cells(RowNr, Col + 2) = Cells(l, 3)
        RowNr = RowNr + 1
        l = l + 1
    Loop While Cells(l, 1) = Cells(l - 1, 1)
    Col = Col + 3
Loop
End Sub

-vemaju
 
Old March 6th, 2005, 12:13 PM
Registered User
 
Join Date: Mar 2005
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Default

thanks vemaju.






Similar Threads
Thread Thread Starter Forum Replies Last Post
Transpose the data yogeshyl Excel VBA 2 September 15th, 2007 11:09 AM
Transpose Tables abc052107 Visual Studio 2005 0 August 23rd, 2007 12:40 AM
How to Transpose this type data jaincafe Access 1 November 27th, 2006 05:58 AM
Help with transpose fegasa Excel VBA 3 April 7th, 2006 03:43 AM
Transpose Rows JpJoe Access 10 March 17th, 2005 08:15 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.