paste to last empty row and beyond

ndendrinos

Well-known Member
Joined
Jan 17, 2003
Messages
1,694
Code:
Sub test()
Sheet1.Select
 Range("A1:B8").Select
Application.CutCopyMode = False
Selection.Copy
Sheet2.Select
Dim LastCell As Range
With ActiveSheet
    Set LastCell = .Cells(.Rows.Count, "A").End(xlUp)
    If IsEmpty(LastCell) Then
         'do nothing
    Else
        Set LastCell = LastCell.Offset(1, 0)
        LastCell.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
    End If
End With
End Sub

Hello, Above code finds the first empty row in Sheet2 and pastes the selection from Sheet1.

I want to add to the code so that it pastes to the last empty row then continues upwards to the next empty row and pastes again and again until it cannot find any empty rows any more.

thank you
 

Excel Facts

Pivot Table Drill Down
Double-click any number in a pivot table to create a new report showing all detail rows that make up that number
quote
then continues upwards to the next empty row
unquote

the operative word is "upwards"

try these code statements.
Code:
with activesheet
.cells(rows.count,"a").end(xlup).end(xlup).offset(-1,0).(do some operation)like pastespecial etc.
end with
suppose you have a15 to A20 is entered and A1 to A0 are blanks
the above code statement takes you to A13

cells(rows.count,"a")) will take you to A65536
the .end(xlup) will take you to A20
the next .end(xlup) will take you A15
the.offset(-1,0) will take you A14

Is this what you want.
 
Upvote 0
Thank you for your rely venkat1926.
I'm still confused so here is a revised scenario.
I'm at sheet 2 and have

A B
1 x
2
3
4 x
5
6
7 x
8
9
10 x

In Sheet 1 the range to copy/paste is A1:B2

A B
1 1 2
2 3 4

After I run the code the result in Sheet 2 S/B

A B
1 x
2 1 2
3 3 4
4 x
5 1 2
6 3 4
7 x
8 1 2
9 3 4
10 x
1 2
3 4

In this example the code pastes to the last empty row and goes up 4 rows and paste again ... up 4 rows and pastes again ... up four rows and pastes again.....until it cannot find any empty cells anymore

Thank you
 
Last edited:
Upvote 0
Is the no of rows and the data to be copied always as uniform as this?
 
Upvote 0

Forum statistics

Threads
1,215,886
Messages
6,127,585
Members
449,385
Latest member
KMGLarson

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