Worksheets: Run-time Error 9

  • Hi,


    I'm a bit lost at why I'm getting Run-time Error 9 (Subscript out of range) for the line Set ws2...



    Thanks.

  • Re: Worksheets: Run-time Error 9


    thampw,



    I've gotten this error myself. Not sure but the Worksheets("") argument needs to be a string. Now I see that the variable is declared as a string but try putting it inside the cstr() function.

  • Re: Worksheets: Run-time Error 9


    Most likely because when execution gets to that line there isn't a sheet named "HiWin04"


    Are you renaming sheets here?
    try
    ThisWorkbook.Worksheets(i).Name = sheet_name(i)
    in the loop
    Pascal

  • Re: Worksheets: Run-time Error 9


    Thanks for the replies. It was odd because I checked the worksheet and the spelling looks correct. However, out of curiousity, I retyped the worksheet name and it worked after that! Don't ask me why though.

  • Re: Worksheets: Run-time Error 9


    thampw,


    After a few times of programming you'll begin to use the trim function on strings because of those leading / trailing spaces. I know alot of my issues can come from them.

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!