+ Reply to Thread
Results 1 to 7 of 7

Edit VBA code to select last cell in named range

  1. #1
    Registered User
    Join Date
    04-05-2012
    Location
    Malaysia
    MS-Off Ver
    Excel 2007
    Posts
    88

    Edit VBA code to select last cell in named range

    Hi everyone,

    I named a range [mranges] with offset formula to make it dynamic, now i need vba code so that selects the last cell in [mranges].

    Please Login or Register  to view this content.
    The last last cell in [mranges] is used to condition another macro.

    P.S
    If anyone could also edit the vba so that it shows the address and value of the last cell in [mranges] via msgbox that would be an extra.

    Thanks.

  2. #2
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,409

    Re: Edit VBA code to select last cell in named range

    Example:

    Please Login or Register  to view this content.

    Regards, TMS
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


  3. #3
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,409

    Re: Edit VBA code to select last cell in named range

    Combining all that ...

    Please Login or Register  to view this content.

    I suspect there may be a better/shorter way but I can't think of it off the top of my head.

    Regards, TMS

  4. #4
    Registered User
    Join Date
    04-05-2012
    Location
    Malaysia
    MS-Off Ver
    Excel 2007
    Posts
    88

    Re: Edit VBA code to select last cell in named range

    Thanks for the quick reply.

    I tested your code, and it works. The msgbox is just to see whether i got the right cell.

    Your code got the address and value correct.

    But I just want to select the address in macro.

    Something like

    Please Login or Register  to view this content.
    I tried, but that only results in invalid qualifier error. Anyway can you please edit it so that the macro selects the cell that contains that value.

    Thanks
    Last edited by rocksan; 07-11-2012 at 03:32 AM. Reason: grammar

  5. #5
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,409

    Re: Edit VBA code to select last cell in named range

    Please Login or Register  to view this content.

    Regards, TMS

  6. #6
    Registered User
    Join Date
    04-05-2012
    Location
    Malaysia
    MS-Off Ver
    Excel 2007
    Posts
    88

    Re: Edit VBA code to select last cell in named range

    Cool your code works flawlessly.

    Also ive found another way to do it,

    Please Login or Register  to view this content.
    Three times today I got my query answered in this forum. Three different people.

    Thank you very much TMShucks.

    Closing the thread now.
    Last edited by rocksan; 07-11-2012 at 03:54 AM. Reason: tags

  7. #7
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,409

    Re: Edit VBA code to select last cell in named range

    You're welcome. Thanks for the rep.

    I knew there would be a shorter way ... thanks for sharing.

    Is your named range just on one row? Your solution seems only to get the last cell on the first row of the named range.

    If your range is rectangular, maybe: [mrange].End(xlToRight).End(xlDown).Select ... although that won't work if it IS a single row.

    Still shorter ...

    Regards, TMS

+ 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