VBA, find last row, copy last row and paste below

Jeffington

New Member
Joined
Mar 22, 2006
Messages
4
Hi, I have a problem that seemingly has been asked in one form or another previously, but not exactly as I need, and I just can't seem to be able to gerrymander those answers to fit my needs.

Essentially my issue is simple, I need to find the last row based on Column B, copy the entire row, then paste directly below. I used to be half decent at this sort of stuff, but haven't had to use it for years so have forgotten. Can someone help a VBA illiterate?
 

Excel Facts

Last used cell?
Press Ctrl+End to move to what Excel thinks is the last used cell.
Hi Jeffington,

Welcome to MrExcel!!

This should do the job:

VBA Code:
Option Explicit
Sub Macro1()

    Dim wsSrc As Worksheet
    Dim lngRowSrc As Long
    
    Application.ScreenUpdating = False
    
    Set wsSrc = ThisWorkbook.Sheets("Sheet1") '<-Sheet name containing the row to be copied. Change to suit if necessary.
    lngRowSrc = wsSrc.Cells(Rows.Count, "B").End(xlUp).Row
    
    wsSrc.Rows(lngRowSrc).Copy Destination:=wsSrc.Rows(lngRowSrc + 1)
    
    Application.ScreenUpdating = True

End Sub

Regards,

Robert
 
Upvote 0
Actually, would it be possible to amend/add to the code such that all data (not formatting) is deleted from the line as well, except the data in column B?
 
Upvote 0
So if you want to only copy the data in the last row of Col. B to the next available row, delete or comment out this line...

VBA Code:
wsSrc.Rows(lngRowSrc).Copy Destination:=wsSrc.Rows(lngRowSrc + 1)

...and use this instead:

VBA Code:
wsSrc.Range("B" & lngRowSrc).Copy Destination:=wsSrc.Range("B" & lngRowSrc + 1)
 
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