Please need help with Transpose,offset,loop -Specially the loop-

frankyalta

New Member
Joined
Nov 8, 2015
Messages
29
Hi Friends,

I have a VBA code that transpose the Column A and B, (everything perfect), But now i'm adding more columns and i need to do the same Transpose but with offset 1 but my code not have a Loop till the last empty column.

Can someone tell me where can i insert the Loop in my code?

This is the code that i'm using

Code:
Public Sub testTranspose()    Dim x As Long
    Dim first_row As Long
    Dim last_row As Long
             
    first_row = 3
    last_row = Range("A" & Rows.Count).End(xlUp).Row
     
    For x = first_row To (last_row) Step 13
        Range("A" & x).Resize(13, 2).Copy
        Range("M" & Rows.Count).End(xlUp).Offset(2).PasteSpecial Transpose:=True
    Next
     
End Sub

THANK YOU !!!!!!!

This is my desire output, see picture :

Excel 2007
ABCDEFGLMNOPQRSTUVWXYZ
1MyDataHeadingPlease I need to Transpose my data as sample bellow
2
3Col-ACol-BCol-CCol-DCol-ECol-F
4A1N14BB27Col-AABCDEFGHIJKLM
5B2O15CC28Col-B12345678910111213
6C3P16DD29
7D4Q17EE30Col-CNOPQRSTVWZYXAA
8E5R18FF31Col-D14151617181920212223242526
9F6S19GG32
10G7T20HH33Col-EBBCCDDEEFFGGHHIIJJKKLLMMNN
11H8V21II34Col-F27282930313233343536373839
12I9W22JJ35
13J10Z23KK36
14K11Y24LL37
15L12X25MM38
16M13AA26NN39
17
18
19
20
21

<tbody>
</tbody>
Sheet2
 

Excel Facts

Why are there 1,048,576 rows in Excel?
The Excel team increased the size of the grid in 2007. There are 2^20 rows and 2^14 columns for a total of 17 billion cells.
See if this works for you:
Code:
Sub testTranspose2()
    Dim first_row As Long, last_row As Long, first_col As Long, last_col As Long, i As Long
    first_row = 3
    first_col = 1
    last_row = Cells(Rows.Count, first_col).End(xlUp).Row
    last_col = Cells(first_row, first_col).End(xlToRight).Column
    Application.ScreenUpdating = False
    For i = 0 To last_col - 1 Step 2
        Range(Cells(first_row, first_col), Cells(last_row, first_col)).Offset(, i).Resize(, 2).Copy
        Range("L" & first_row + 1 + i * 1.5).PasteSpecial Transpose:=True
    Next i
    Application.CutCopyMode = False
    Application.ScreenUpdating = True
End Sub
 
Last edited:
Upvote 0
Hi Tetra201,


It work perfect!!, I tough that i just need to add an snippet in my code, i was wrong...

Thank you !!
 
Upvote 0

Forum statistics

Threads
1,221,418
Messages
6,159,791
Members
451,589
Latest member
Harold14

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