VBA for Combing all data into a single column

Alex0013

Board Regular
Joined
Jul 23, 2014
Messages
158
Office Version
  1. 365
Platform
  1. Windows
Hi All,

This may already be answered on here, but couldn't find exactly what I was looking for...

I want to take this, data pasted into Excel as rows, with varying lengths of columns (can assume I paste into Column B):

abc
defgh
ij
klmnopqrst
u
v
wxyz

<tbody>
</tbody>












And convert to this, a single column with all the data and no blank rows (Can assuming I want this in the same sheet in Column A):
a
b
c
d
e
f
g
h
i
j
k
l
m
n
o
p
q
r
s
t
u
v
w
x
y
z

<tbody>
</tbody>


Any help on this would be amazing!
Thanks!

Excel 2016 64-bit
 

Excel Facts

Which came first: VisiCalc or Lotus 1-2-3?
Dan Bricklin and Bob Frankston debuted VisiCalc in 1979 as a Visible Calculator. Lotus 1-2-3 debuted in the early 1980's, from Mitch Kapor.
How about
Code:
Sub TransposeAll()
   Dim Iary As Variant, Oary As Variant
   Dim r As Long, c As Long, i As Long
   
   Iary = Range("B1").CurrentRegion.value2
   ReDim Oary(1 To UBound(Iary) * UBound(Iary, 2), 1 To 2)
   
   For r = 1 To UBound(Iary)
      For c = 1 To UBound(Iary, 2)
         If Iary(r, c) <> "" Then
            i = i + 1
            Oary(i, 1) = Iary(r, c)
         End If
      Next c
   Next r
   Range("A1").Resize(i).Value = Application.Index(Oary, 0, 1)
End Sub
 
Upvote 0
I have no clue what Fluff has written and I bow to his/her expertise.

However I've written this so I'll post it

Code:
Sub OneCol()
    Dim c As Range
    Dim col As New Collection
    
    'get all cell values into a collection
    For Each c In Me.UsedRange
        If c <> "" Then col.Add (c)
    Next c
    
    'clear the sheet
    Me.UsedRange.Clear
    
    'write all values back to col A
    For i = 1 To col.Count
        Range("A" & i) = col(i)
    Next i
    
End Sub
 
Upvote 0
another method
Code:
Sub t()
Dim c As Range
With ActiveSheet
    Columns(1).Insert
        For Each c In .Range("B2", .Cells(Rows.Count, 2).End(xlUp))
            If c <> "" Then
                .Range(c, .Cells(c.Row, Columns.Count).End(xlToLeft)).Copy
                .Cells(Rows.Count, 1).End(xlUp)(2).PasteSpecial xlPasteValues, Transpose:=True
            End If
        Next
        .UsedRange.Offset(, 1).ClearContents
End With
End Sub
 
Upvote 0

Forum statistics

Threads
1,215,336
Messages
6,124,331
Members
449,155
Latest member
ravioli44

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