+ Reply to Thread
Results 1 to 5 of 5

Copy Row Down One

Hybrid View

  1. #1
    Registered User
    Join Date
    06-03-2010
    Location
    Seattle
    MS-Off Ver
    Excel 2003
    Posts
    4

    Question Copy Row Down One

    Hi All,
    I'm using this code from another thread, but I want it to copy data down a row instead over a column. I tried this code, but it didn't work! Could you help me fix it?

    Private Sub Worksheet_Change(ByVal Target As Range)
    Dim LC As Long
    LC = Cells(1, Rows.Count).End(xlToDown).Row
        If Not Intersect(Target, Range("A2:J2")) Is Nothing Then
            Application.EnableEvents = False
            Range("A2:J2").Copy Cells(1, LC + 1)
            Application.EnableEvents = True
        End If
    End Sub
    Should be easy for you Excel programming experts!

    Thanks in advance!

  2. #2
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Copy Row Down One

    Like so:
    Private Sub Worksheet_Change(ByVal Target As Range)
    Dim LR As Long
    LR = Cells(Rows.Count, 1).End(xlToDown).Row
        
        If Not Intersect(Target, Range("A2:J2")) Is Nothing Then
            Application.EnableEvents = False
                Range("A2:J2").Copy Cells(LR + 1, 1)
            Application.EnableEvents = True
        End If
    End Sub
    Last edited by JBeaucaire; 05-05-2011 at 11:47 AM.
    _________________
    Microsoft MVP 2010 - Excel
    Visit: Jerry Beaucaire's Excel Files & Macros

    If you've been given good help, use the icon below to give reputation feedback, it is appreciated.
    Always put your code between code tags. [CODE] your code here [/CODE]

    ?None of us is as good as all of us? - Ray Kroc
    ?Actually, I *am* a rocket scientist.? - JB (little ones count!)

  3. #3
    Registered User
    Join Date
    06-03-2010
    Location
    Seattle
    MS-Off Ver
    Excel 2003
    Posts
    4

    Re: Copy Row Down One

    Quote Originally Posted by JBeaucaire View Post
    Like so:
    Private Sub Worksheet_Change(ByVal Target As Range)
    Dim LR As Long
    LR = Cells(1, Rows.Count).End(xlToDown).Row
        
        If Not Intersect(Target, Range("A2:J2")) Is Nothing Then
            Application.EnableEvents = False
                Range("A2:J2").Copy Cells(LR + 1, 1)
            Application.EnableEvents = True
        End If
    End Sub
    Hi JBeaucaire,
    Thanks for the quick and helpful response. I'm getting an error with your code though.
    This seems to be causing the problem...

    LR = Cells(1, Rows.Count).End(xlToDown).Row

    I've attached my macro-enabled Excel spreadsheet for you to take a look at.
    Again, thank you so much for the help!
    Cheers.
    Attached Files Attached Files

  4. #4
    Forum Contributor
    Join Date
    06-17-2010
    Location
    Dallas, TX
    MS-Off Ver
    Excel 2010
    Posts
    157

    Re: Copy Row Down One

    Try this instead.

    LR = Cells(Rows.Count, 1).End(xlUp).Row

  5. #5
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Copy Row Down One

    My bad, I didn't swap the params:
    LR = Cells(Rows.Count, 1).End(xlToDown).Row

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Tags for this Thread

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