Copying the Last 10 Rows in a Given Column

keeper10

New Member
Joined
Jul 28, 2014
Messages
13
Hey all, I need to copy the last 10 rows in column B. Once I do that I am going to paste them into another sheet. I am just new to VBA and don't know how to do this. Thanks!
 

Excel Facts

Will the fill handle fill 1, 2, 3?
Yes! Type 1 in a cell. Hold down Ctrl while you drag the fill handle.
Try this:
Code:
Sub CopyLines()

    Dim LastRow As Long

    LastRow = Sheets("Sheet1").Cells(Rows.Count, "B").End(xlUp).Row

    Sheets("Sheet1").Range("B" & LastRow - 9 & ":B" & LastRow).Copy Sheets("Sheet2").Range("A1")

End Sub
 
Upvote 0
Here is code that will select the last 10 rows in column B (if there are less than 10 rows, it will select all rows).
Code:
    'Find last row in column B
    Dim myLastRow As Long
    myLastRow = Cells(Rows.Count, "B").End(xlUp).Row
    
    'Select last 10 rows in column B
    If myLastRow >= 10 Then
        Range(Cells(myLastRow - 9, "B"), Cells(myLastRow, "B")).Select
    Else
        Range("B1:B" & myLastRow).Select
    End If
It could be written a little shorter, but I broke it out so you can easier understand the logic.

To copy, just change the .Select references with .Copy.
 
Upvote 0

Forum statistics

Threads
1,223,228
Messages
6,170,871
Members
452,363
Latest member
merico17

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