Copying cells to a single column

jake_barnes

Board Regular
Joined
Sep 29, 2005
Messages
55
I'm currently using the code below to take an active range (about 700-800 rows, 5-7 columns) and, skipping empty cells, copy it to a single column. The code works like a champ, but it's slow. Like, one cell per second slow. Any idea how to speed things up?

Sub RequisitionColumn()
Dim rData As Range
Dim r As Range, c As Range
Dim rStart As Range
Dim counter As Integer

Set rData = Selection
On Error Resume Next
Application.DisplayAlerts = False
Set rStart = Application.InputBox(Prompt:="Select the location for the requisition loading.", Title:="Select Output Location", Type:=8)
On Error GoTo 0
Application.DisplayAlerts = True
If rStart Is Nothing Then Exit Sub
For Each r In rData.Rows
For Each c In rData.Columns
If Not IsEmpty(Cells(r.Row, c.Column)) Then
rStart.Offset(counter, 0) = Cells(r.Row, c.Column)
counter = counter + 1
End If
Next c
Next r
End Sub
 

Excel Facts

How to calculate loan payments in Excel?
Use the PMT function: =PMT(5%/12,60,-25000) is for a $25,000 loan, 5% annual interest, 60 month loan.
I am trying to make your code do something using random data. Can you tell me how it is supposed work? Thanks.
 
Upvote 0
Code:
Sub copyit()
Dim u(), e
With Selection
ReDim u(1 To .Cells.Count, 1 To 1)
For Each e In .Value
    If Len(e) > 0 Then k = k + 1: u(k, 1) = e
Next e
If k > 0 Then Range("K1").Resize(k) = u
End With
End Sub
 
Upvote 0
Code:
Sub copyit()
Dim u(), e
With Selection
ReDim u(1 To .Cells.Count, 1 To 1)
For Each e In .Value
    If Len(e) > 0 Then k = k + 1: u(k, 1) = e
Next e
If k > 0 Then Range("K1").Resize(k) = u
End With
End Sub

This was certainly quick, but I need to read the cells across the rows first.
 
Upvote 0
How about?
Code:
Sub copyit2()
Dim u(), e, rs
With Selection
ReDim u(1 To .Cells.Count, 1 To 1)
For Each rs In .Rows
    For Each e In rs.Value
    If Len(e) > 0 Then k = k + 1: u(k, 1) = e
Next e, rs
If k > 0 Then Range("K1").Resize(k) = u
End With
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,609
Messages
6,179,875
Members
452,949
Latest member
Dupuhini

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