Form Control Macro for copying the last row of data to the end

TGirl66

New Member
Joined
Dec 6, 2024
Messages
7
Office Version
  1. 365
Platform
  1. Windows
I need a macro button to copy the last row of filtered data and add it to the end. In this example, the the macro would copy row 10 (TLP Kenswick) and copy/paste it to Row11.

1733514605633.png


Filtered here it would take Conroe (row 8) and also pasting to the open row (11). Is this possible? Thank you so much!

1733514752098.png
 

Attachments

  • 1733514543581.png
    1733514543581.png
    25.9 KB · Views: 8
Last edited by a moderator:
Okay, in that case, see if this does what you want...

VBA Code:
Option Explicit

Sub CopyLastRow()

    Dim targetSheet As Worksheet
    Dim lastColumn As Long
    Dim lastRow As Long
    
    Set targetSheet = ThisWorkbook.Worksheets("Sheet1")
    
    With targetSheet
        lastColumn = .Cells(1, .Columns.Count).End(xlToLeft).Column
    End With
    
    'clear contents for Row 26
    With targetSheet
        .Range(.Cells(26, 1), .Cells(26, lastColumn)).ClearContents
    End With
    
    lastRow = targetSheet.Range("A26").End(xlUp).Row
    
    'clear filter (optional)
    With targetSheet
        If .FilterMode Then .ShowAllData
    End With
    
    If lastRow >= 3 Then
        With targetSheet
            .Range(.Cells(lastRow, "A"), .Cells(lastRow, lastColumn)).Copy .Range("A26")
        End With
    Else
        MsgBox "No data found.", vbExclamation
    End If
    
End Sub

Hope this helps!
 
Upvote 0

Excel Facts

Get help while writing formula
Click the italics "fx" icon to the left of the formula bar to open the Functions Arguments dialog. Help is displayed for each argument.
Okay, in that case, see if this does what you want...

VBA Code:
Option Explicit

Sub CopyLastRow()

    Dim targetSheet As Worksheet
    Dim lastColumn As Long
    Dim lastRow As Long
   
    Set targetSheet = ThisWorkbook.Worksheets("Sheet1")
   
    With targetSheet
        lastColumn = .Cells(1, .Columns.Count).End(xlToLeft).Column
    End With
   
    'clear contents for Row 26
    With targetSheet
        .Range(.Cells(26, 1), .Cells(26, lastColumn)).ClearContents
    End With
   
    lastRow = targetSheet.Range("A26").End(xlUp).Row
   
    'clear filter (optional)
    With targetSheet
        If .FilterMode Then .ShowAllData
    End With
   
    If lastRow >= 3 Then
        With targetSheet
            .Range(.Cells(lastRow, "A"), .Cells(lastRow, lastColumn)).Copy .Range("A26")
        End With
    Else
        MsgBox "No data found.", vbExclamation
    End If
   
End Sub

Hope this helps!
You've been extremely helpful, I appreciate it. Happy Holidays.
 
Upvote 0

Forum statistics

Threads
1,224,592
Messages
6,179,789
Members
452,942
Latest member
VijayNewtoExcel

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