+ Reply to Thread
Results 1 to 14 of 14

Code to find last Column keeps causing an error

  1. #1
    Forum Contributor
    Join Date
    05-13-2012
    Location
    Atlanta, GA
    MS-Off Ver
    Excel 2010
    Posts
    378

    Question Code to find last Column keeps causing an error

    I have the following code...

    Please Login or Register  to view this content.
    I would like the code to copy the last populated Column as well as the last populated row. It currently works fine with the last populated row but it only copies the first 4 columns and the number of columns varies on each worksheet. I have tried some different variation of writing for the last column but it keeps on causing errors. PLEASE HELP!!!!


    Thanks!
    Last edited by dwhite30518; 06-01-2012 at 03:38 PM. Reason: Forum Rules Violation

  2. #2
    Valued Forum Contributor StevenM's Avatar
    Join Date
    03-23-2008
    Location
    New Lenox, IL USA
    MS-Off Ver
    2007
    Posts
    910

    Re: Code to find last Column keeps causing an error

    Assuming the last column can be found in row 1:

    Add:
    Please Login or Register  to view this content.
    For example:

    Please Login or Register  to view this content.

  3. #3
    Forum Contributor
    Join Date
    05-13-2012
    Location
    Atlanta, GA
    MS-Off Ver
    Excel 2010
    Posts
    378

    Re: Code to find last Column keeps causing an error

    I adjusted the code as follows...

    Please Login or Register  to view this content.
    I now get an error with this line of code.

    Please Login or Register  to view this content.
    If I redo the code like this...

    Please Login or Register  to view this content.
    It only copies the first column to the destination worksheet. How do I fix this?

  4. #4
    Valued Forum Contributor StevenM's Avatar
    Join Date
    03-23-2008
    Location
    New Lenox, IL USA
    MS-Off Ver
    2007
    Posts
    910

    Re: Code to find last Column keeps causing an error

    If it is With some worksheet, such as:

    Please Login or Register  to view this content.
    then you need a dot in front of Cells & Columns (or Rows).

    So it should be:

    Please Login or Register  to view this content.
    The following code does nothing, its purpose is to illustrate many ways to find the last row/column.

    Please Login or Register  to view this content.

  5. #5
    Forum Contributor
    Join Date
    05-13-2012
    Location
    Atlanta, GA
    MS-Off Ver
    Excel 2010
    Posts
    378

    Re: Code to find last Column keeps causing an error

    I want to select a range based on the last populated row and last populated column. Is the above code correct?

  6. #6
    Forum Contributor
    Join Date
    05-13-2012
    Location
    Atlanta, GA
    MS-Off Ver
    Excel 2010
    Posts
    378

    Re: Code to find last Column keeps causing an error

    Lets try this....I want to pull the data from specific column Headers on each worksheet within my workbook. What would be the best way to accomplish this?

  7. #7
    Forum Contributor
    Join Date
    05-13-2012
    Location
    Atlanta, GA
    MS-Off Ver
    Excel 2010
    Posts
    378

    Re: Code to find last Column keeps causing an error

    Examples...

    I have Columns "Item Number" and "Actual Failure" that I would like to pull from each worksheet and paste into a "Master" worksheet but have "item number" data paste into column A and have "actual Failure" data copy into column B.

  8. #8
    Valued Forum Contributor StevenM's Avatar
    Join Date
    03-23-2008
    Location
    New Lenox, IL USA
    MS-Off Ver
    2007
    Posts
    910

    Re: Code to find last Column keeps causing an error

    Could you upload your workbook (or a mockup of your workbook)?

  9. #9
    Forum Contributor
    Join Date
    05-13-2012
    Location
    Atlanta, GA
    MS-Off Ver
    Excel 2010
    Posts
    378

    Re: Code to find last Column keeps causing an error

    Examples...

    I have Columns "Item Number" and "Actual Failure" that I would like to pull from each worksheet and paste into a "Master" worksheet but have "item number" data paste into column A and have "actual Failure" data copy into column B.

  10. #10
    Forum Contributor
    Join Date
    05-13-2012
    Location
    Atlanta, GA
    MS-Off Ver
    Excel 2010
    Posts
    378

    Re: Code to find last Column keeps causing an error

    This is the workbook I am working with.
    Attached Files Attached Files

  11. #11
    Forum Expert tigeravatar's Avatar
    Join Date
    03-25-2011
    Location
    Colorado, USA
    MS-Off Ver
    Excel 2003 - 2013
    Posts
    5,361

    Re: Code to find last Column keeps causing an error

    dwhite30518,

    Using your posted workbook, something like this should work for you:
    Please Login or Register  to view this content.
    Hope that helps,
    ~tigeravatar

    Forum Rules: How to use code tags, mark a thread solved, and keep yourself out of trouble

  12. #12
    Forum Contributor
    Join Date
    05-13-2012
    Location
    Atlanta, GA
    MS-Off Ver
    Excel 2010
    Posts
    378

    Re: Code to find last Column keeps causing an error

    I will have to try this when I get out of traffic and at home. Am I reading this code right...will this copy the data from just the item mulberry column and the actual failure column and this paste the data to the summary tab?

  13. #13
    Valued Forum Contributor StevenM's Avatar
    Join Date
    03-23-2008
    Location
    New Lenox, IL USA
    MS-Off Ver
    2007
    Posts
    910

    Re: Code to find last Column keeps causing an error

    Please Login or Register  to view this content.

  14. #14
    Forum Contributor
    Join Date
    05-13-2012
    Location
    Atlanta, GA
    MS-Off Ver
    Excel 2010
    Posts
    378

    Re: Code to find last Column keeps causing an error

    This works beautifully!! Thank you very much!!!

+ 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