macro to transpose Data

howard

Well-known Member
Joined
Jun 26, 2006
Messages
6,603
Office Version
  1. 2021
Platform
  1. Windows
I have data that starts in F1 and the range can at times stretch to O15-see some sample data below




Book1
FGH
1933305933316933317
2985140985147
3955815955478955147
Sheet1




I need a macro to transpose an copy the data in Col Q from row 1 onwards-I should look as follows once the macro has run



Book1
Q
1933305
2933316
3933317
4985140
5985147
6955815
7955478
8955147
Sheet1


Your assistance in resolving this is much appreciated
 
Last edited:

Excel Facts

Select a hidden cell
Somehide hide payroll data in column G? Press F5. Type G1. Enter. Look in formula bar while you arrow down through G.
Re: mqcro to transpose Data

How about
Code:
Sub TransposeData()
   Dim ary As Variant
   Dim Nary() As Variant
   Dim r As Long, c As Long, i As Long
   ary = Intersect(ActiveSheet.UsedRange, Range("F:O"))
   For r = 1 To UBound(ary)
      For c = 1 To UBound(ary, 2)
         If Not IsEmpty(ary(r, c)) Then
            ReDim Preserve Nary(0 To i)
            Nary(UBound(Nary)) = ary(r, c)
            i = i + 1
         End If
      Next c
   Next r
   Range("Q1").Resize(i).Value = Application.Transpose(Nary)
End Sub
 
Upvote 0
.. data that starts in F1 and the range can at times stretch to O15
With such a small maximum range I think you could work directly in the worksheet with no detrimental speed effect.
Code:
Sub SingleColumn()
  Dim r As Long
  Dim c As Range
  
  For Each c In Range("F1:O15")
    If Len(c.Value) > 0 Then
      r = r + 1
      Cells(r, 17).Value = c.Value
    End If
  Next c
End Sub
 
Upvote 0
Thanks for the help guys, much appreciated
 
Upvote 0

Forum statistics

Threads
1,224,824
Messages
6,181,186
Members
453,020
Latest member
Mohamed Magdi Tawfiq Emam

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