+ Reply to Thread
Results 1 to 25 of 25

Find last cell in a spreadshhet using VBA

  1. #1
    Registered User
    Join Date
    07-13-2010
    Location
    London
    MS-Off Ver
    Excel 2003
    Posts
    11

    Find last cell in a spreadshhet using VBA

    Hello everyone

    Im currently working on a spreadsheet at work and im trying to automate it a bit using VBA.

    The problem i have is that i am trying to find the last cell with data in column A, column a is full of formulas and when i use the End(xlDown) code it just keeps ending up with the last cell with a formula in but i want it to be the last cell with actual data in

    Please help
    Last edited by steve_m_2003; 11-29-2011 at 06:15 AM.

  2. #2
    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: Find last cell in a spreadshhet using VBA

    Hi,

    Not quite sure what you mean by 'data' but
    Please Login or Register  to view this content.
    will return the vlalue of the last cell in column A to the variable vCellLast

    Regards
    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.

  3. #3
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,167

    Re: Find last cell in a spreadshhet using VBA

    Are you trying to say you would like to find the last cell that has values and not formulae?
    If I have 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]

  4. #4
    Registered User
    Join Date
    07-13-2010
    Location
    London
    MS-Off Ver
    Excel 2003
    Posts
    11

    Re: Find last cell in a spreadshhet using VBA

    Hi agasin thanks for the replys sorry i havnt i have been off work. Thaqnks richard but thats not really what i was after

    Arlu yes i am needing excel to goto the last cell with a value in instead of going to the last cell with a formula in

    I dont think i explained myself as good as i could have sorry

    Hope someone can help me

    Thanks in advance

  5. #5
    Forum Expert JapanDave's Avatar
    Join Date
    06-10-2008
    Location
    The grid, I got in!
    MS-Off Ver
    Excel 2010/13
    Posts
    1,696

    Re: Find last cell in a spreadshhet using VBA

    How about this?

    Please Login or Register  to view this content.

  6. #6
    Registered User
    Join Date
    07-13-2010
    Location
    London
    MS-Off Ver
    Excel 2003
    Posts
    11

    Re: Find last cell in a spreadshhet using VBA

    Quote Originally Posted by JapanDave View Post
    How about this?

    Please Login or Register  to view this content.

    Thanks but i cant get it to work it does nothing

  7. #7
    Valued Forum Contributor Steffen Thomsen's Avatar
    Join Date
    10-15-2010
    Location
    Kolding, Denmark
    MS-Off Ver
    Excel 2007 and Excel 2010
    Posts
    953

    Re: Find last cell in a spreadshhet using VBA

    This will ignore formulae and select the last row that has data
    Please Login or Register  to view this content.
    Last edited by Steffen Thomsen; 11-28-2011 at 07:55 AM.
    Please take time to read the forum rules

  8. #8
    Registered User
    Join Date
    07-13-2010
    Location
    London
    MS-Off Ver
    Excel 2003
    Posts
    11

    Re: Find last cell in a spreadshhet using VBA

    Quote Originally Posted by Steffen Thomsen View Post
    This will ignore formulae and select the last row that has data
    Please Login or Register  to view this content.
    Thanks i have copied it into vba and it has a problem

    Expected: list separtor or )

    So i put a bracket around A like so

    Please Login or Register  to view this content.
    But then it gives me another error of Invalid Qualifier and highlights

    Please Login or Register  to view this content.

  9. #9
    Valued Forum Contributor john55's Avatar
    Join Date
    10-23-2010
    Location
    Europe
    MS-Off Ver
    Excel for Microsoft 365
    Posts
    2,060

    Re: Find last cell in a spreadshhet using VBA

    hi,
    as an option
    see if it helps you
    Please Login or Register  to view this content.
    Regards, John55
    If you have issues with Code I've provided, I appreciate your feedback.
    In the event Code provided resolves your issue, please mark your Thread as SOLVED.
    If you're satisfied by any members response to your issue please use the star icon at the lower left of their post.

    ...enjoy -funny parrots-

  10. #10
    Valued Forum Contributor Steffen Thomsen's Avatar
    Join Date
    10-15-2010
    Location
    Kolding, Denmark
    MS-Off Ver
    Excel 2007 and Excel 2010
    Posts
    953

    Re: Find last cell in a spreadshhet using VBA

    Sorry, missing a character, updated a bit

    Please Login or Register  to view this content.
    Last edited by Steffen Thomsen; 11-28-2011 at 08:23 AM.

  11. #11
    Registered User
    Join Date
    07-13-2010
    Location
    London
    MS-Off Ver
    Excel 2003
    Posts
    11

    Re: Find last cell in a spreadshhet using VBA

    Quote Originally Posted by Steffen Thomsen View Post
    Sorry, missing a character, updated a bit

    Please Login or Register  to view this content.
    Thanks

    For some reason it keeps selecting cell A502

    My spreadsheet is 504 rows long and about 50 columns wide and everycell has a forumla to pull the information from all different sheets however it varies day to day how much information goes into it but it never goes past row 504 sometimes there maybe 50 rows worth of data or could be 500 rows of data. This data then needs to be copied into a master spreadsheet to which i do manually but i was trying to make it automatic with vba. The first row of data that gets copied is row 5 and then highlight all the way down to the ast row with data in, like i said it could be row 50 or row 500 but as every row has a formula in i think vba looks at that instead of a value.

    Hope this explains it a bit better and i am greatly appericated for all your kind help

    Steve

    Everycell in

  12. #12
    Valued Forum Contributor Steffen Thomsen's Avatar
    Join Date
    10-15-2010
    Location
    Kolding, Denmark
    MS-Off Ver
    Excel 2007 and Excel 2010
    Posts
    953

    Re: Find last cell in a spreadshhet using VBA

    Ok, then try this:

    Please Login or Register  to view this content.
    Last edited by Steffen Thomsen; 11-28-2011 at 09:36 AM.

  13. #13
    Registered User
    Join Date
    07-13-2010
    Location
    London
    MS-Off Ver
    Excel 2003
    Posts
    11

    Re: Find last cell in a spreadshhet using VBA

    Quote Originally Posted by Steffen Thomsen View Post
    Ok, then try this:

    Please Login or Register  to view this content.
    It goes to row 503 which i dont understand as the last row is 504 but in my test spreadsheet the last row with a value that the formula returned is 446 but it skips past that and goes to row 503

    Sorry about this

  14. #14
    Valued Forum Contributor Steffen Thomsen's Avatar
    Join Date
    10-15-2010
    Location
    Kolding, Denmark
    MS-Off Ver
    Excel 2007 and Excel 2010
    Posts
    953

    Re: Find last cell in a spreadshhet using VBA

    If you need to copy the range then use this:
    This copies the range to another sheet

    Please Login or Register  to view this content.
    *EDIT

    use this to see if it selects the correct range

    Please Login or Register  to view this content.

  15. #15
    Forum Expert JapanDave's Avatar
    Join Date
    06-10-2008
    Location
    The grid, I got in!
    MS-Off Ver
    Excel 2010/13
    Posts
    1,696

    Re: Find last cell in a spreadshhet using VBA

    I don't know if it is what you are after, but anyway.

    Please Login or Register  to view this content.

  16. #16
    Registered User
    Join Date
    07-13-2010
    Location
    London
    MS-Off Ver
    Excel 2003
    Posts
    11

    Re: Find last cell in a spreadshhet using VBA

    Nope none of these are working i dont have a clue what is going on but ill stick to my good old trustworthy copy and paste manually

    Thanks for all the hhelp tho people

  17. #17
    Forum Moderator jeffreybrown's Avatar
    Join Date
    02-19-2009
    Location
    Cibolo, TX
    MS-Off Ver
    Office 365
    Posts
    10,327

    Re: Find last cell in a spreadshhet using VBA

    Haven't really followed any of the other suggestions, but try this.

    In column A the formula goes down to A17, but the last value is in A5.
    Attached Files Attached Files
    HTH
    Regards, Jeff

  18. #18
    Forum Expert JapanDave's Avatar
    Join Date
    06-10-2008
    Location
    The grid, I got in!
    MS-Off Ver
    Excel 2010/13
    Posts
    1,696

    Re: Find last cell in a spreadshhet using VBA

    How about you post a dummy workbook with sensitive info taken out, so we can actually see what you want.

  19. #19
    Registered User
    Join Date
    07-13-2010
    Location
    London
    MS-Off Ver
    Excel 2003
    Posts
    11

    Re: Find last cell in a spreadshhet using VBA

    Quote Originally Posted by jeffreybrown View Post
    Haven't really followed any of the other suggestions, but try this.

    In column A the formula goes down to A17, but the last value is in A5.
    Thanks for your input this has half worked, it has given me thwe cell to which i need selecting but i have tried to change the code to select the cell instead of given me a msg box.

    I have attached a file to which may help you help me

    In this sample the formulas on sheet 1 are looking at sheet 2 but the original looks at many different sheets. But on this sheet 1 i am trying to get vba to select the last cell with a value which is A457 (although its not always A457)

    Again thanks for all your help
    Attached Files Attached Files

  20. #20
    Valued Forum Contributor
    Join Date
    08-29-2011
    Location
    Mississauga, CANADA
    MS-Off Ver
    Excel 2010
    Posts
    503

    Re: Find last cell in a spreadshhet using VBA

    Here you go.
    it will select the last row with data and not a formula.
    Please mark the thread as SOLVED if it is

    Please Login or Register  to view this content.

  21. #21
    Registered User
    Join Date
    07-13-2010
    Location
    London
    MS-Off Ver
    Excel 2003
    Posts
    11

    Re: Find last cell in a spreadshhet using VBA

    Quote Originally Posted by Kelshaer View Post
    Here you go.
    it will select the last row with data and not a formula.
    Please mark the thread as SOLVED if it is

    Please Login or Register  to view this content.


    This selects cell A1 which contains the column labels which have been hand written and do not include a formula, sorry forgot to put column labels on the sample here is a new one
    Attached Files Attached Files

  22. #22
    Valued Forum Contributor Steffen Thomsen's Avatar
    Join Date
    10-15-2010
    Location
    Kolding, Denmark
    MS-Off Ver
    Excel 2007 and Excel 2010
    Posts
    953

    Re: Find last cell in a spreadshhet using VBA

    This single line will select the last row with a value in it

    Please Login or Register  to view this content.

  23. #23
    Forum Moderator jeffreybrown's Avatar
    Join Date
    02-19-2009
    Location
    Cibolo, TX
    MS-Off Ver
    Office 365
    Posts
    10,327

    Re: Find last cell in a spreadshhet using VBA

    On your sample, this selects cell A458

    Please Login or Register  to view this content.

  24. #24
    Valued Forum Contributor
    Join Date
    08-29-2011
    Location
    Mississauga, CANADA
    MS-Off Ver
    Excel 2010
    Posts
    503

    Re: Find last cell in a spreadshhet using VBA

    Please Login or Register  to view this content.

  25. #25
    Registered User
    Join Date
    07-13-2010
    Location
    London
    MS-Off Ver
    Excel 2003
    Posts
    11

    Re: Find last cell in a spreadshhet using VBA

    Thats great thankyou everyone for your support

+ 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