MACRO to copy and transpose data in a column

bh9aq

New Member
Joined
Jun 21, 2006
Messages
4
Hi there,

Im trying to create a Macro which can do the following: Go to the selected cell when Macro is run, keep going down cell by cell until it finds a blank cell, select the values, copy them and paste them by transposing into the cell next to where it started from in a row, carry on doing this procedure and pasting the transposed values next to the first non blank value until it gets to the end of this column. Can you please help me with this Macro. Help will be greatly appreciated.

Regards
 

Excel Facts

Ambidextrous Undo
Undo last command with Ctrl+Z or Alt+Backspace. If you use the Undo icon in the QAT, open the drop-down arrow to undo up to 100 steps.
If I understand you correctly, try this:
Code:
Sub test()
    lr = Cells(Rows.Count, Selection.Column).End(xlUp).Row
    fr = ActiveCell.Row
    c = ActiveCell.Column
    For i = fr To lr
        Range(Cells(i, c), Cells(lr, c)).Copy
        Cells(i, c + 1).PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=True
    Next i
End Sub
 
Upvote 0
Thanks for your response. Let me try to explain that again. I have values in a column as below:
1
2
3
5
6

8
7
4
9

4
3

etc. so after a set of numbers I have blank cells. what I want the Macro to do is to start at the first value, keep coming down until it finds the blank cell which is after 6, now copy from 1-6 and paste it in the next column as a row i-e transpose values from 1-6 and paste them next to value 1 then keep going down after the blank cell, come to value 8 and keep going down until the next blank is found which is after the value 9, copy values from 8-9 and paste them in a row next to 8....carry on this process until the values end in that column. The above code pastes the values in columns and keeps cascading in next columns until its only showing one value in the last column if you know what I mean

Thanks for your help.
 
Upvote 0
I think this ought to do it

Code:
Sub test2()
    Dim t As Range, u As Range
    c = ActiveCell.Column
    fr = ActiveCell.Row
    lr = Cells(Rows.Count, c).End(xlUp).Row
    r = fr
    Do
        Set t = Cells(r, c)
        Set u = t.End(xlDown)
        Range(t, u).Copy
        t.Offset(, 1).PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=True
        r = u.End(xlDown).Row
    Loop While r < lr
    Application.CutCopyMode = False
End Sub
 
Upvote 0
Thank you very much...its greatly appreciated.

You've made me save a lot of my time.

Thanks
 
Upvote 0
I think this ought to do it

Code:
Sub test2()
    Dim t As Range, u As Range
    c = ActiveCell.Column
    fr = ActiveCell.Row
    lr = Cells(Rows.Count, c).End(xlUp).Row
    r = fr
    Do
        Set t = Cells(r, c)
        Set u = t.End(xlDown)
        Range(t, u).Copy
        t.Offset(, 1).PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=True
        r = u.End(xlDown).Row
    Loop While r < lr
    Application.CutCopyMode = False
End Sub


Thanks so much for your code. It is exactly what I am looking for. But would you mind to suggest a modification to make it paste to the next row instead of the first row of each set of records?

i.e.

1 12356
2 8749
3 43
5
6


8
7
4
9


4
3

Thanks a lot!
 
Upvote 0

Forum statistics

Threads
1,224,596
Messages
6,179,807
Members
452,943
Latest member
Newbie4296

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top