Simple Loop for Copy and Paste

RHONDAK72

Board Regular
Joined
Dec 26, 2007
Messages
133
I use Excel 2013. I have values listed in Column A of Sheet 1. I want to copy each value from Column A and paste the value into Column B of Sheet 2 as long as the cell from Column A of Sheet 1 is not blank or null. (Once the cell is blank or null, then it has reached the end of the populated cells and so the process should end at that point.)

Example:
If cell A2 of Sheet 1 is not blank or null, then copy and paste the value to B2 of Sheet 2.
Next, loop to next cell and continue.
Else, if cell A2 of Sheet 1 is blank or null, then end the loop.

If cell A3 of Sheet 1 is not blank or null, then copy and paste the value to B3 of Sheet 2.
Next, loop to next cell and continue.
Else, if cell A3 of Sheet 1 is blank or null, then end the loop.

If cell A4 of Sheet 1 is not blank or null, then copy and based the value of B4 of Sheet 2.
Next, loop to next cell and continue.
Else, if cell A4 of Sheet 1 is blank or null, then end the loop.

And so on…

How would you code the loop this?
 

Excel Facts

What do {} around a formula in the formula bar mean?
{Formula} means the formula was entered using Ctrl+Shift+Enter signifying an old-style array formula.
Try this:

Code:
Sub Copy_Range()
Application.ScreenUpdating = False
Dim i As Long
Dim Lastrow As Long
Lastrow = Sheets(1).Cells(Rows.Count, "A").End(xlUp).Row
Sheets(1).Activate
Dim Lastrowa As Long
Lastrowa = Sheets(2).Cells(Rows.Count, "A").End(xlUp).Row + 1
    
    
    For i = 1 To Lastrow
        If Sheets(1).Cells(i, 1).Value <> "" Then Cells(i, 1).Copy Sheets(2).Cells(Lastrowa, 2): Lastrowa = Lastrowa + 1
    Next
Application.ScreenUpdating = True
End Sub
 
Upvote 0

Forum statistics

Threads
1,215,563
Messages
6,125,560
Members
449,237
Latest member
Chase S

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