+ Reply to Thread
Results 1 to 8 of 8

Thread: Copy last row only

  1. #1
    Registered User
    Join Date
    12-12-2011
    Location
    Essex
    MS-Off Ver
    Excel 2010
    Posts
    19

    Copy last row only

    I am referencing, to copy the rows from file A.xls to B.xls.
    Every week I add new rows to file A.xls which I expect to appear in B.xls
    Rather than me having to pull the cell down every week in B.xls to copy these new data of A.xls
    Is it possible that rows appear automatically in B.xls when I update the file A.xls.

    (Note: I am adding new rows and not updating the present row)

  2. #2
    Forum Moderator arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    4,371

    Re: Copy last row only

    Rather than me having to pull the cell down every week in B.xls to copy these new data of A.xls
    What do you mean by this? Why do you have to pull down the cell every week? Does the cell have formulae that automatically brings in the values from A.xls?
    Cheers,
    Arlette

    If I helped, Don't forget to add to my reputation (click on the star below the post)
    Don't forget to mark threads as "Solved" (Thread Tools->Mark thread as Solved)
    Use code tags when posting your VBA code: [code] Your code here [/code]

  3. #3
    Registered User
    Join Date
    12-12-2011
    Location
    Essex
    MS-Off Ver
    Excel 2010
    Posts
    19

    Re: Copy last row only

    Yes, I have referenced a row of B.xls to the row of A.xls

    For example, 1st row of A is linked to B by formula. When I add a second row to A it should automatically appear in B. Rather than me having to drag down the row of B to get the new row.

    Makes sense ?

  4. #4
    Forum Moderator arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    4,371

    Re: Copy last row only

    You can drag the formula in B.xls for about 1000 rows in advance. So that whenever data is added to A.xls, you do not have to drag them each time a row is added.
    By the way, what is the formula that you are using in B.xls?
    Cheers,
    Arlette

    If I helped, Don't forget to add to my reputation (click on the star below the post)
    Don't forget to mark threads as "Solved" (Thread Tools->Mark thread as Solved)
    Use code tags when posting your VBA code: [code] Your code here [/code]

  5. #5
    Registered User
    Join Date
    12-12-2011
    Location
    Essex
    MS-Off Ver
    Excel 2010
    Posts
    19

    Re: Copy last row only

    That may not solve my problem because I am referencing different files in single sheet. So linking 1000 rows will disable other linked file. Basically I want the last three latest rows of A to appear in B because that's what I care about. Same for all the linked file. For eg last three rows of file A,C,D,E to appear in File B.

    Regarding the formula I just type "=" in cell of file B.xls and clicking on the cell of A.xls I want to copy and excel will auto reference.

  6. #6
    Forum Moderator arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    4,371

    Re: Copy last row only

    Oh ok, got your point. Please upload a sample file with dummy data in the same format as A.xls and B.xls, so we can understand it better.
    Cheers,
    Arlette

    If I helped, Don't forget to add to my reputation (click on the star below the post)
    Don't forget to mark threads as "Solved" (Thread Tools->Mark thread as Solved)
    Use code tags when posting your VBA code: [code] Your code here [/code]

  7. #7
    Registered User
    Join Date
    12-12-2011
    Location
    Essex
    MS-Off Ver
    Excel 2010
    Posts
    19

    Re: Copy last row only

    It contains the date like text,numbers and date (Just take random data pls). So we have to find the row containing the last non-zero data and copy it to B.xls from A.xls.

  8. #8
    Forum Moderator arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    4,371

    Re: Copy last row only

    You can use this code. Its not very efficient but works fine. You can use it till we get a better solution
    Option Explicit
    Dim lrow1 As Long
    Dim lrow2 As Long
    Dim noofrows As Long
    
    Sub compare_files()
    
    lrow1 = Workbooks("A.xls").Worksheets(1).Range("A" & Rows.Count).End(xlUp).Row
    lrow2 = Workbooks("B.xls").Worksheets(1).Range("A" & Rows.Count).End(xlUp).Row
    
    If lrow1 <> lrow2 And lrow1 > lrow2 Then
       noofrows = lrow1 - lrow2
       Workbooks("A.xls").Worksheets(1).Range("A" & lrow2 + 1 & ":C" & lrow2 + noofrows).Copy _
       Workbooks("B.xls").Worksheets(1).Range("A" & Rows.Count).End(xlUp).Offset(1, 0)
    End If
    End Sub
    I have considered dummy data in columns A to C.
    Cheers,
    Arlette

    If I helped, Don't forget to add to my reputation (click on the star below the post)
    Don't forget to mark threads as "Solved" (Thread Tools->Mark thread as Solved)
    Use code tags when posting your VBA code: [code] Your code here [/code]

+ 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.2.0