Urgent--macro for transposing data

HUZZAIN

New Member
Joined
Jan 25, 2016
Messages
8
Hi there,

Im trying to create a Macro which can do the following: Start selecting from a1 till blank column and coming down till blank row cell by cell , select the all above values, copy them and paste them by transposing them AFTER tWo blank columns, carry on doing this procedure and pasting the transposed values . Can you please help me with this Macro. Help will be greatly appreciated.
eg;
columnA columnB blank column blank column[TABLE="width: 320"]
<colgroup><col width="64" span="5" style="width: 48pt;"></colgroup><tbody>[TR]
[TD="width: 64"][/TD]
[TD="class: xl65, width: 64"][/TD]
[TD="class: xl66, width: 64"][/TD]
[TD="class: xl67, width: 64"][/TD]
[TD="class: xl68, width: 64"][/TD]
[/TR]
</tbody>[/TABLE]
[TABLE="width: 362"]
<colgroup><col><col></colgroup><tbody>[TR]
[TD]Demir (Serum)[/TD]
[TD]16[/TD]
[/TR]
[TR]
[TD]Demir bağlama kapasitesi[/TD]
[TD]362[/TD]
[/TR]
[TR]
[TD]Glukoz [/TD]
[TD]109[/TD]
[/TR]
[TR]
[TD]HBA1C[/TD]
[TD]5,6[/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]Demir (Serum)[/TD]
[TD]41[/TD]
[/TR]
[TR]
[TD]Demir bağlama kapasitesi[/TD]
[TD]215[/TD]
[/TR]
[TR]
[TD]Ferritin [/TD]
[TD]56,46[/TD]
[/TR]
[TR]
[TD]Glukoz [/TD]
[TD]101[/TD]
[/TR]
[TR]
[TD]HBA1C[/TD]
[TD]5,8[/TD]
[/TR]
</tbody>[/TABLE]

transpose the data to 2nd blank column .
help will be greatly apppreciated.
 

Excel Facts

Does the VLOOKUP table have to be sorted?
No! when you are using an exact match, the VLOOKUP table can be in any order. Best-selling items at the top is actually the best.
If I understand what you need to do, this code should work

Code:
Sub Transpose()


Dim rData As Range


Set rData = ActiveSheet.Range("A1", Cells(Rows.Count, "B").End(xlUp))


rData.Copy


ActiveSheet.Range("E1").PasteSpecial Transpose:=True


End Sub
 
Upvote 0
thankyou for the reply but the code is giving an error on the following line ,
ActiveSheet.Range("E1").PasteSpecial Transpose:=True
my excel is in different language,its saying that the selection is not matching the paste area.
 
Upvote 0
ı guess the code is selecting whole data and transposing it thats y its giving an error of not getting the space to transpose.
suppose ı have the following data .
1 j
2 f
4 f
5 g

7 jj
8 kk
9 kk
3 uu

4 ll
6 uu
7 oo

what i want the code to do is to transpose data like below
1 2 3 5
j f f g

ı want it to copy in the column d,e,f,g,h etc with their respective value.
 
Upvote 0
Try this:
Code:
Sub Huzzain()
Dim lrow As Integer
Dim lcolumn As Integer

lrow = Cells(Rows.Count, 1).End(xlUp).Row
Range("A1:B" & lrow).Copy

Cells(1, 4).PasteSpecial Transpose:=True

Nexti:
lcolumn = Cells(1, Columns.Count).End(xlToLeft).Column

For i = 4 To lcolumn
    If Cells(1, i) = "" Then
        Columns(i).Delete
        i = i - 1
        GoTo Nexti
    End If
Next i


End Sub
 
Last edited:
Upvote 0
Thanks but i didnt work its taking all the data and transposing it
1 j
2 f
4 f
5 g

7 jj
8 kk
9 kk
3 uu

4 ll
6 uu
7 oo

what i want the code to do is to transpose data like below

1 2 3 5

j f f g

7 8 9 3
jj kk kk uu


 
Upvote 0
Perhaps
Code:
Sub test()
    Dim oneArea As Range
    Dim oneValueSet As Variant
    Dim maxCol As Long, i As Long
    
    With Range("A:A")
        For Each oneArea In .SpecialCells(xlCellTypeConstants).Areas
            With oneArea.CurrentRegion
                If maxCol < .Rows.Count Then maxCol = .Rows.Count
                oneValueSet = .Value
                .ClearContents
                .Resize(.Columns.Count).Insert
                With .Offset(-.Columns.Count, 0)
                    .Resize(.Columns.Count, .Rows.Count).Value = Application.Transpose(oneValueSet)
                End With
            End With
        Next oneArea
        
        For i = .Cells(.Rows.Count, 1).End(xlUp).Row To 2 Step -1
            With Cells(i, 1)
                If .Value & .Offset(-1, 0) = vbNullString Then
                    .Resize(1, maxCol).Delete
                End If
            End With
        Next i
    End With
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,719
Messages
6,174,089
Members
452,542
Latest member
Bricklin

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