Macro transfer data from a column with a twist

Elfiraon

New Member
Joined
Sep 10, 2014
Messages
31
Hey all,

I'm trying to create a macro that will do the following:

When macro is activated; In a column (eg. column A) go to the first cell that has a value other than "0" and then copy, then keep going down cell by cell until it finds a blank cell, once the values are selected, copy and paste them in a different column (eg. column B or column A of different sheet).

Any input/help is appreciated, thanks!
 

Excel Facts

Can you sort left to right?
To sort left-to-right, use the Sort dialog box. Click Options. Choose "Sort left to right"
Try this:

Code:
Option Explicit


Sub copyZero()
    Dim lr As Long
    lr = Range("A" & Rows.Count).End(xlUp).Row
    Dim newR As Long
    Dim i As Long
    
    Application.ScreenUpdating = False
    For i = 1 To lr
    newR = Range("B" & Rows.Count).End(xlUp).Row
    If Range("A" & i) <> 0 Then
    Range("A" & i).Copy Range("B" & newR + 1)
    End If
    Next i
    Application.CutCopyMode = False
    Application.ScreenUpdating = True
    MsgBox "complete"


End Sub
 
Upvote 0

Forum statistics

Threads
1,215,465
Messages
6,124,977
Members
449,200
Latest member
Jamil ahmed

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