+ Reply to Thread
Results 1 to 7 of 7

How to refer the last worksheet ?

  1. #1
    Registered User
    Join Date
    02-25-2012
    Location
    ghaziabaad,india
    MS-Off Ver
    Excel 2003
    Posts
    9

    How to refer the last worksheet ?

    Hi Everyone,

    I need a macro which brings me to the last sheet in a particular excel file when i have no idea about how many sheets are there.For example if we know 5 sheets are there we can use Set trg = wrk.Worksheets(5) but if dont know the total no. of sheets generated how could we go to last sheet ???

    Thanx
    Ravi

  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
    36,272

    Re: How to refer the last worksheet ?

    Maybe (not tested):

    Please Login or Register  to view this content.

    Regards, TMS
    Trevor Shuttleworth - Excel Aid

    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
    Registered User
    Join Date
    02-25-2012
    Location
    ghaziabaad,india
    MS-Off Ver
    Excel 2003
    Posts
    9

    Re: How to refer the last worksheet ?

    Thanx TM its working.

  4. #4
    Forum Expert OnErrorGoto0's Avatar
    Join Date
    12-30-2011
    Location
    I DO NOT POST HERE ANYMORE
    MS-Off Ver
    I DO NOT POST HERE ANYMORE
    Posts
    1,655

    Re: How to refer the last worksheet ?

    Safer to specify the workbook for the count too, and either use Sheets consistently, or Worksheets:
    Please Login or Register  to view this content.
    Good luck.

  5. #5
    Valued Forum Contributor
    Join Date
    10-15-2007
    Location
    Home
    MS-Off Ver
    Office 2010, W10
    Posts
    373

    Re: How to refer the last worksheet ?

    Hi

    Maybe it would be better instead of Sheets.Count to use Worksheets.Count, in case there are other sheets not type worksheet.

  6. #6
    Valued Forum Contributor
    Join Date
    10-15-2007
    Location
    Home
    MS-Off Ver
    Office 2010, W10
    Posts
    373

    Re: How to refer the last worksheet ?

    P. S.

    I mean, Ravi, if you are referring to worksheets:

    Please Login or Register  to view this content.

  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
    36,272

    Re: How to refer the last worksheet ?

    Well, the OP has said it is working for him. And, as OEG0 has suggested, it would be good to be consistent about the use of "Sheets" or "Worksheets". I guess the OP will know if there are any other sheets in the mix and could come back to discuss the implications.

    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