+ Reply to Thread
Results 1 to 18 of 18

Finding the last used cell in the active column and paste copied data

  1. #1
    Forum Contributor
    Join Date
    08-02-2012
    Location
    Austria
    MS-Off Ver
    Excel 2007
    Posts
    457

    Finding the last used cell in the active column and paste copied data

    Hi all,

    I have a master workbook where I run a maro to open a bunch of xml documents and copy data from them. Not all the workbooks have the same headings on the same place. So my macro looks for a certain name of the heading and then he copies that data only, goes back to the master workbook and looks for the same heading and paste it there. The problem I have is that I need to tell them with finalrow where to put the data. but since I use the
    Please Login or Register  to view this content.
    it will always check the same column, if for a reason the next column to copy is in another column, it will paste it wrong.

    How can I paste in the column that is active and taking in acount that the data for the first time goes in the 3rd row and not the first (in row 1 there is the macro button and row 2 has the headings of the master workbook).

    Please see my code and let me know changes I need to make:

    Please Login or Register  to view this content.
    Thanks in advance and greetings.

  2. #2
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: Finding the last used cell in the active column and paste copied data

    Try

    Please Login or Register  to view this content.
    will find the next empty row on entire columns.

  3. #3
    Forum Contributor
    Join Date
    08-02-2012
    Location
    Austria
    MS-Off Ver
    Excel 2007
    Posts
    457

    Re: Finding the last used cell in the active column and paste copied data

    Hi AB33,
    Thank you for your answer. How can I implement your line of code in my macro? Do I need to put the text I'm looking for in the "*" ??
    I tried the code just like above, but it does not do nothing, so I have no clue how to use the code.

    Greetings.
    (seems my previous answer got lost)

  4. #4
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: Finding the last used cell in the active column and paste copied data

    I am not quite sure what the issue is. You said, you want to find the last non empty row in a data.
    You have

    Please Login or Register  to view this content.
    which finds the last non empty row in column "A" ONLY, while my line will do the same, but it finds in all columns, not just column A.

  5. #5
    Forum Contributor
    Join Date
    08-02-2012
    Location
    Austria
    MS-Off Ver
    Excel 2007
    Posts
    457

    Re: Finding the last used cell in the active column and paste copied data

    Hi AB33,
    It should be that the new data to be pasted is in the last row that is not empty +1 row. so it goes on the empty cell without overwritting the previous data.
    If I understand this, I need to change the:
    Please Login or Register  to view this content.
    with your line?

    I will give it a try to see what it will do. (I'm still green in excel vba).

    Greetings.

  6. #6
    Forum Contributor
    Join Date
    08-02-2012
    Location
    Austria
    MS-Off Ver
    Excel 2007
    Posts
    457

    Re: Finding the last used cell in the active column and paste copied data

    Hi AB33,

    I tried your code. I replaced the line with your code and it works great on the first column, when if finds the next text for the next column, it paste the data on the wrong spot. It goes and compares column 1 and then paste the new data acording to the last row +1.
    Not sure where I go wrong.

    Greetings.

  7. #7
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: Finding the last used cell in the active column and paste copied data

    Yes, but your code require almost full heart surgery, not minor one.

    You are trying to match a header and copy that column with the header in to master sheet. I have done some few lines to give you some direction.

    Please Login or Register  to view this content.
    Last edited by AB33; 11-12-2013 at 05:35 AM.

  8. #8
    Forum Contributor
    Join Date
    08-02-2012
    Location
    Austria
    MS-Off Ver
    Excel 2007
    Posts
    457

    Re: Finding the last used cell in the active column and paste copied data

    Hi AB33,

    Thanks for your code. Actually the first problem I did encounter was that the line "With wbk.UsedRange" failed.
    I got the error: Run-time error '438": Object doesn't support this property or method

    In my previous code the FinalRow did remember on which line it was last, maybe just reseting the finalrow will do the trick.
    Do you have any idea how I could reset it so it will take the new row number?

    Greetings.

  9. #9
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: Finding the last used cell in the active column and paste copied data

    I have amended it. Try it again.

  10. #10
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: Finding the last used cell in the active column and paste copied data

    Or better, could you please attach a sample of both destination and source sheets.

  11. #11
    Forum Contributor
    Join Date
    08-02-2012
    Location
    Austria
    MS-Off Ver
    Excel 2007
    Posts
    457

    Re: Finding the last used cell in the active column and paste copied data

    Hi AB33,

    Sorry, but I can't attach workbook now.

    I can give you some details about the look of the workbook.

    The master workbook is like:

    Row1 Macro button

    Row2: /Tester1 in cell A2, /Tester2 in cell B2 and so on

    (the rest of the rows below row 2 are empty)


    One XML file in the same folder where the macro workbook is:

    Row 1 has the headers, /Tester1 in cell A1, /Tester2 in cell B2 and so on

    Row 2 starts with the data. (some times the next XML file in the folder has 1 to 2 columns less information. The amounts of rows depends from a few to a few hundreds.


    So the macros needs to find the same name of the header and copy that range, than paste it in the next empty row in the same column that the header is with the same name. Some times when there is an extra column, there is only information in 1 row.
    If the columns would be always the same, then it would be much easier to make the macro, but since I have the columns on different places, it needs to have the finalrow shifting into the active column.

    Sorry for my green knowledge of vba and no clue how to ask what I need.

    Greetings.

  12. #12
    Forum Contributor
    Join Date
    08-02-2012
    Location
    Austria
    MS-Off Ver
    Excel 2007
    Posts
    457

    Re: Finding the last used cell in the active column and paste copied data

    Hi AB33,

    Any solutions possible ;-)

    Greetings.

  13. #13
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: Finding the last used cell in the active column and paste copied data

    I am not sure if you can understand the attached code and should be able to amend it. I wrote it for similar thread, but there are few tweaks need to be done.
    Please Login or Register  to view this content.
    These two lines are from the source sheet. The first line refers to a row and the second line to each cell in row 1.
    So, the code match each cell with the headings on the master sheet.
    If you are looking for a single word, you do not need these two lines. Instead, you substitute sfind by the search word.
    Please Login or Register  to view this content.
    You also need to change this path which is mine in to your own folder.

    Please Login or Register  to view this content.
    Attached Files Attached Files

  14. #14
    Forum Contributor
    Join Date
    08-02-2012
    Location
    Austria
    MS-Off Ver
    Excel 2007
    Posts
    457

    Re: Finding the last used cell in the active column and paste copied data

    Hi AB33,

    As I have Excel 2003 and are not able to open it, any chance this can be exported so I can open it?

    Thanks a lot and greetings.

  15. #15
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: Finding the last used cell in the active column and paste copied data

    Sorry!
    I did not notice your profile.
    Attached Files Attached Files

  16. #16
    Forum Contributor
    Join Date
    08-02-2012
    Location
    Austria
    MS-Off Ver
    Excel 2007
    Posts
    457

    Re: Finding the last used cell in the active column and paste copied data

    HI AB33,

    I did give it a try, but to difficult for me to get things goin.
    I managed today to make the previous macro work for 100%. The only thing I miss is that if the macro looks for a word in the column and it does not find it, then it should not stop the code but continue (I think it is error traping).
    Let's say one workbook does not have the column /Tester3, then it should skip it and go looking for /Tester4.

    the part that this would be handy are those columns, but the tricky part is that this one has only one cell with data in the column. So it would copy that cell, go to the master workbook and past it in the correct possition. when it makes again a pass to the same column and will paste it in the cell that coresponds to the same row with the new data. But still I guess this will be really complicated to make it work.

    Greetings.

  17. #17
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: Finding the last used cell in the active column and paste copied data

    Could you please post the code which does not work 100%.

  18. #18
    Forum Contributor
    Join Date
    08-02-2012
    Location
    Austria
    MS-Off Ver
    Excel 2007
    Posts
    457

    Re: Finding the last used cell in the active column and paste copied data

    Hi AB33,

    Sorry for not answering ealier, I have just to many things going on and I can't work on this. As soon as I have more time, I will come back to it.

    Greetings.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Selecting Range from Active Cell to Last Row with data in same column
    By bs04do in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 08-23-2013, 10:59 AM
  2. Can't paste copied cell
    By Jaron_t in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 12-12-2012, 08:47 PM
  3. Copy values from cell in active row, paste in first empty cell in spesified column.
    By Test123Test in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 02-19-2012, 05:20 PM
  4. How to paste only numeric data of a copied column
    By perfection in forum Excel General
    Replies: 8
    Last Post: 10-07-2010, 08:45 AM
  5. Finding last cell in a column, select, copy/paste
    By GaretJjax in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 11-16-2008, 05:17 PM

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