+ Reply to Thread
Results 1 to 15 of 15

Cycle through worksheets code not quite right

  1. #1
    Forum Contributor
    Join Date
    01-28-2010
    Location
    Pittsburgh, PA
    MS-Off Ver
    Excel 2013
    Posts
    200

    Cycle through worksheets code not quite right

    Hello everyone. I am trying to cycle through around 20-30 sheets in a workbook and do a find and replace for links pulled in an array. I want to skip the first two, so basically start at 3. I will always start at worksheet 3, though the name for worksheet 3 may change.

    When I enter this code, nothing happens:

    Please Login or Register  to view this content.
    However if I put
    'Sheets(wsCount).Select' after the Set 'ws = Sheets(wsCount)' line, it works through most sheets then at the end it says "Select Method Of Worksheet class failed."

    I know this code is not quite right - any suggestions? At least how do I get rid of that error?

    If you have any efficiency increases (like you don't think the loop is good) that is fine too, I'm open to criticism.

    Thanks!

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

    Re: Cycle through worksheets code not quite right

    Instead of this
    Please Login or Register  to view this content.
    use
    Please Login or Register  to view this content.
    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]

  3. #3
    Forum Expert nilem's Avatar
    Join Date
    10-22-2011
    Location
    Ufa, Russia
    MS-Off Ver
    2013
    Posts
    3,377

    Re: Cycle through worksheets code not quite right

    maybe so (not tested)
    Please Login or Register  to view this content.

  4. #4
    Forum Contributor
    Join Date
    01-28-2010
    Location
    Pittsburgh, PA
    MS-Off Ver
    Excel 2013
    Posts
    200

    Re: Cycle through worksheets code not quite right

    Arlette,

    Still getting the error. It occurs when trying to update the very last tab.For more info, I have 9 worksheets but want to start at 3 and go to 9 (want this to be dynamic as more sheets may be added over time.) When I step through, for some reason it goes past the "count" and starts looking for a worksheet 10, which doesn't exist. I clearly count 9. Why would it be looking for a 10th if it should be counting?

  5. #5
    Forum Contributor
    Join Date
    08-22-2012
    Location
    nj, us
    MS-Off Ver
    Excel 2010
    Posts
    163

    Re: Cycle through worksheets code not quite right

    send file pls

  6. #6
    Forum Contributor
    Join Date
    01-28-2010
    Location
    Pittsburgh, PA
    MS-Off Ver
    Excel 2013
    Posts
    200

    Re: Cycle through worksheets code not quite right

    Nilem,

    A good approach but the problem is that I'm not replacing that range. I've used the range on an input ws (one of the ones I am trying to skip) to fill an array of worksheet names, then selecting each worksheet via the array in the input and then just searching the worksheet for the value to replace. Still lost on why it's trying to count the extra worksheet.

  7. #7
    Forum Contributor
    Join Date
    01-28-2010
    Location
    Pittsburgh, PA
    MS-Off Ver
    Excel 2013
    Posts
    200

    Re: Cycle through worksheets code not quite right

    John, huge apologies but due to the sensitive nature of the work I can't share the file. It would give you inside info and rich and get me jail or fired . Believe me, I would have shared from the start if I could have.

  8. #8
    Forum Contributor
    Join Date
    01-28-2010
    Location
    Pittsburgh, PA
    MS-Off Ver
    Excel 2013
    Posts
    200

    Re: Cycle through worksheets code not quite right

    Interestingly, I played with this a bit and using some code I was able to trap the names of all the spreadsheets in an array and then display them - I found there was a 10th sheet that isn't even hidden since I don't have the chance called LinkingMetaData. A quick search doesn't turn up much info. What could this be? Could it be do to all the external links I have?

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

    Re: Cycle through worksheets code not quite right

    I have not heard about that type of tab either. From where do you get your file? From sharepoint?

  10. #10
    Forum Contributor
    Join Date
    01-28-2010
    Location
    Pittsburgh, PA
    MS-Off Ver
    Excel 2013
    Posts
    200

    Re: Cycle through worksheets code not quite right

    No, it's just a link from a bunch of external Excel files. I don't see anything about it on Google. It's at the end so I can temporarily fix it by getting rid of the Worksheets.Count and just putting in the actual number of worksheets one short of the total, but that kind of kills the dynamic aspect. I wish I knew what was creating this hidden worksheet, and I can't seem to even unhide it.

  11. #11
    Forum Guru JosephP's Avatar
    Join Date
    03-27-2012
    Location
    Ut
    MS-Off Ver
    2003/10
    Posts
    7,328

    Re: Cycle through worksheets code not quite right

    it's probably a very hidden sheet-can you see it in the vb editor? it might also be an old excel 5 module depending on how old your workbook is
    Josie

    if at first you don't succeed try doing it the way your wife told you to

  12. #12
    Forum Contributor
    Join Date
    01-28-2010
    Location
    Pittsburgh, PA
    MS-Off Ver
    Excel 2013
    Posts
    200

    Re: Cycle through worksheets code not quite right

    Good call, I can see it in the VBA editor. Anyway I can see the contents of it?

  13. #13
    Forum Guru JosephP's Avatar
    Join Date
    03-27-2012
    Location
    Ut
    MS-Off Ver
    2003/10
    Posts
    7,328

    Re: Cycle through worksheets code not quite right

    change its visible property in the properties window of the vb editor

  14. #14
    Forum Contributor
    Join Date
    01-28-2010
    Location
    Pittsburgh, PA
    MS-Off Ver
    Excel 2013
    Posts
    200

    Re: Cycle through worksheets code not quite right

    It was completely blank and causing so many problems. Thank you so much for your help JosephP!

  15. #15
    Forum Contributor
    Join Date
    01-28-2010
    Location
    Pittsburgh, PA
    MS-Off Ver
    Excel 2013
    Posts
    200

    Re: Cycle through worksheets code not quite right

    It's solved though, so they did

+ 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