+ Reply to Thread
Results 1 to 4 of 4

Insert new row at bottom of data range

Hybrid View

  1. #1
    Registered User
    Join Date
    12-12-2012
    Location
    London
    MS-Off Ver
    Excel 2007
    Posts
    16

    Insert new row at bottom of data range

    Hi all

    I am looking to create a macro that would repeat the bottom row of a data range directly underneath, and then delete the data contained within certain cells within that row (ie, A50, B50, D50, G50 only).

    However, I don't seem to be able to insert a piece of code that tells the macro to repeat the last row, no matter where the last row is located (ie row 50, or row 51).

    Is there any way of doing this?

    Thanks guys

  2. #2
    Forum Expert Mumps1's Avatar
    Join Date
    10-10-2012
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2010, 365
    Posts
    8,026

    Re: Insert new row at bottom of data range

    This code will repeat the last row:

    Sub CopyRow()
        Dim bottomA As Integer
        bottomA = Range("a" & Rows.Count).End(xlUp).Row
        Rows(bottomA).Copy Cells(Rows.Count, "A").End(xlUp).Offset(1, 0)
    End Sub

  3. #3
    Registered User
    Join Date
    08-26-2012
    Location
    India
    MS-Off Ver
    Excel 2003
    Posts
    58

    Re: Insert new row at bottom of data range

    try this...may be helpful for what you are looking for


    Sub Macro1()
    
        Range("A1").Select
        Selection.End(xlDown).Select
        Selection.EntireRow.Select
        
        Selection.Copy
        ActiveCell.Offset(1, 0).Select
        ActiveSheet.Paste
        Application.CutCopyMode = False
        
        RNO = ActiveCell.Row
       
        
        Cells(RNO, 2).ClearContents '< CHANGE HERE THE COLUMN NUMBER
        Cells(RNO, 3).ClearContents
        Cells(RNO, 4).ClearContents
        
        Cells(RNO, 1).Select
         
         
        
    End Sub

  4. #4
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: Insert new row at bottom of data range

    Hi,

    If there is nothing below your range then

    Sub CopyRowDeleteCells()
        Dim rDelete As Range, lRow As Long
        lRow = Range("A" & Rows.Count).End(xlUp).Row
        Range("A" & lRow).EntireRow.Copy Destination:=Range("A" & lRow + 1)
        Set rDelete = Application.Union(Cells(lRow + 1, "A"), Cells(lRow + 1, "B"), Cells(lRow + 1, "D"), Cells(lRow + 1, "G"))
        rDelete.ClearContents
    
    End Sub
    Richard Buttrey

    RIP - d. 06/10/2022

    If any of the responses have helped then please consider rating them by clicking the small star icon below the post.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1