Transpose entire excel document

caroline1991

New Member
Joined
Jun 2, 2015
Messages
6
I have a question about transposing colums to rows.

I know that you can copy/paste and insert special and click transpose. But is it possible to transpose an entire excel document, when everything is in one colume, and then somehow notify excel that each time there is an empty cell it has to switch to a new row, when transposing??

I hope this is understandable and someone has a tip or 2 :)
 

Excel Facts

Round to nearest half hour?
Use =MROUND(A2,"0:30") to round to nearest half hour. Use =CEILING(A2,"0:30") to round to next half hour.
Hi Caroline,

Welcome aboard!

The following VBA sample will do the requested transposition with a couple of conditions.

1. The single column of data is column A
2. There is a single blank cell between the groups in column A

Deviations from the above will require code modification.

The transposition will start in column B and will leave the original data in column A untouched.

In a standard module:

Code:
Public Sub Test()

Dim oCell As Range
Dim oTarget As Range
Dim oTranspose As Range

Set oTarget = ActiveSheet.Range("A1:A" & ActiveSheet.Range("A" & Rows.Count).End(xlUp).Row)
Set oTranspose = ActiveSheet.Range("B1")

For Each oCell In oTarget
    If oCell.Value <> "" Then
        oTranspose.Value = oCell.Value
        Set oTranspose = oTranspose.Offset(0, 1)
    Else
        Set oTranspose = oTranspose.Offset(1, ((oTranspose.Column - 2) * -1))
    End If
Next oCell

End Sub
 
Upvote 0

Some explanation on this line please..
Code:
((oTranspose.Column - 2) * -1))

I tested it. It works so great. The thing is if there are two or three blanks, the code drop two or three rows too.
How to drop a row only if there many blanks?

Am not the poster. Just wanna study. Sorry for the jump in.

Thank you very much
 
Upvote 0
The thing is if there are two or three blanks, the code drop two or three rows too.
That was expected per my condition #2 of post #2. It shouldn't be too difficult to make it deal with multiple blanks either inline or in a seperate procedure.

Code:
Set oTranspose = oTranspose.Offset(1, ((oTranspose.Column - 2) * -1))

It is starting the transpose in column B (1 column offset), the "If" clause above had already moved to the next column (another column offset), hence "Column-2". Then multiply by minus 1 to yield negative Column offset and of course a 1 row positive offset.
 
Upvote 0
Here's a modified sample that should deal with multiple adjacent blank cells:

Rich (BB code):
Public Sub Test2()

Dim oCell As Range
Dim oTarget As Range
Dim oTranspose As Range

Set oTarget = ActiveSheet.Range("A1:A" & ActiveSheet.Range("A" & Rows.Count).End(xlUp).Row)
Set oTranspose = ActiveSheet.Range("B1")

For Each oCell In oTarget

    If oCell.Value = "" And oCell.Offset(1, 0).Value = "" Then
    
    ElseIf oCell.Value <> "" Then
        oTranspose.Value = oCell.Value
        Set oTranspose = oTranspose.Offset(0, 1)
    Else
        Set oTranspose = oTranspose.Offset(1, ((oTranspose.Column - 2) * -1))
    End If
    
Next oCell

End Sub
 
Upvote 0

Forum statistics

Threads
1,214,646
Messages
6,120,717
Members
448,985
Latest member
chocbudda

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