VBA Paste at Last Row + 1 -- Not Working

MarkRCC

New Member
Joined
May 22, 2017
Messages
46
Hi All,

I have used VBA to paste a range below the last active cell in the paste to good success, but for some reason I cannot seem to get it to work in this instance.

I have two named ranges that I am trying to move into one single column, but rather than building a combined list, the second range is overlapping on the first.

The code I am using is as follows:

Code:
Sub GeneratePlantList()
Dim lr As Long
Set ws = ThisWorkbook.Sheets("Index")
Set dom = ThisWorkbook.Sheets("Domain")

lastRow = ActiveSheet.Cells(Rows.Count, "F").End(xlUp).Row

ws.Range("TreeRange").Copy
dom.Range("F" & lastRow + 1).PasteSpecial Paste:=xlPasteValues

ws.Range("TreeRange2").Copy
dom.Range("F" & lastRow + 1).PasteSpecial Paste:=xlPasteValues

The first "TreeRange" is going below the column header fine, and then "TreeRange2" pastes into the same spot below the header, rather than at the end of the first "TreeRange"

What am I doing wrong this time?

Thanks in advance
 

Excel Facts

What did Pito Salas invent?
Pito Salas, working for Lotus, popularized what would become to be pivot tables. It was released as Lotus Improv in 1989.
Hello MarcRCC,

You need to recalculate the Last Row after you paste the first time. As a side note, you rarely need to select objects in VBA before performing an operation. Selecting greatly slows do your code.

Code:
Sub GeneratePlantList()


    Dim lr As Long


        Set ws = ThisWorkbook.Sheets("Index")
        Set dom = ThisWorkbook.Sheets("Domain")


        lastRow = ActiveSheet.Cells(Rows.Count, "F").End(xlUp).Row


        ws.Range("TreeRange").Copy
        dom.Range("F" & lastRow + 1).PasteSpecial Paste:=xlPasteValues


        lastRow = ActiveSheet.Cells(Rows.Count, "F").End(xlUp).Row
        ws.Range("TreeRange2").Copy
        dom.Range("F" & lastRow + 1).PasteSpecial Paste:=xlPasteValues
 
Upvote 0

Forum statistics

Threads
1,223,911
Messages
6,175,325
Members
452,635
Latest member
laura12345

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