+ Reply to Thread
Results 1 to 8 of 8

why doesnt this work

  1. #1
    Registered User
    Join Date
    08-02-2012
    Location
    London, England
    MS-Off Ver
    Excel 2003
    Posts
    3

    Unhappy why doesnt this work

    I found this script on the excel forum but i get an error that the following line:

    Worksheets(ShtCtr).Name = Worksheets(ShtCtr).Range("B2").Text

    is a 1009 error application defined or object defined error

    here is the full script:

    Option Explicit
    Sub RenameSheets()
    Dim ShtCtr As Double

    For ShtCtr = 1 To Worksheets.Count
    Worksheets(ShtCtr).Name = Worksheets(ShtCtr).Range("B2").Text
    Next ShtCtr

    End Sub


    the way i see this vba is that its supposed to extract the text in cell b2 and name the worksheet as such? Please advise on how to correct this.

    M.S.

  2. #2
    Forum Moderator zbor's Avatar
    Join Date
    02-10-2009
    Location
    Croatia
    MS-Off Ver
    365 ProPlus
    Posts
    15,607

    Re: why doesnt this work

    Your post does not comply with Rule 3 of our Forum RULES. Use code tags around code. Posting code without them makes your code hard to read and difficult to be copied for testing. Highlight your code and click the # at the top of your post window. For more information about these and other tags, found here

  3. #3
    Forum Guru Pete_UK's Avatar
    Join Date
    12-31-2011
    Location
    Warrington, England
    MS-Off Ver
    Office 2019 (still learning)
    Posts
    24,765

    Re: why doesnt this work

    Why have you put it in a loop? Are you trying to rename every sheet the same?

    Pete

  4. #4
    Registered User
    Join Date
    08-02-2012
    Location
    London, England
    MS-Off Ver
    Excel 2003
    Posts
    3

    Re: why doesnt this work

    I found this script on the excel forum but i get an error that the following line:

    Worksheets(ShtCtr).Name = Worksheets(ShtCtr).Range("B2").Text

    is a 1009 error application defined or object defined error

    here is the full script:

    Please Login or Register  to view this content.
    the way i see this vba is that its supposed to extract the text in cell b2 and name the worksheet as such? Please advise on how to correct this.

    M.S.

    ---------- Post added at 02:46 PM ---------- Previous post was at 02:44 PM ----------

    No, i actually didnt notice the loop. I just need to name every sheet based on what a cell i.e. b2 says for each respective sheet. Ideally i would also want it to use only some part of the text in B2 rather than all, but i am a complete beginner in VBA. If you could advise i would be highly thankful

  5. #5
    Forum Expert
    Join Date
    09-27-2011
    Location
    Poland
    MS-Off Ver
    Excel 2007
    Posts
    1,312

    Re: why doesnt this work

    Hi
    try maybe this:
    Please Login or Register  to view this content.
    Of course every range B2 text should be different
    Regards

    tom1977

    If You are satisfied with my solution click the small star icon on the left to say thanks.

  6. #6
    Registered User
    Join Date
    08-02-2012
    Location
    London, England
    MS-Off Ver
    Excel 2003
    Posts
    3

    Re: why doesnt this work

    Hi Tom 1977 - I just tried running it and it gave me thesame 1004 error as previously for thesame line. What should i put instead of range B2 (may be thats where my error is)?

    Cheers,

    Max

  7. #7
    Forum Expert
    Join Date
    09-27-2011
    Location
    Poland
    MS-Off Ver
    Excel 2007
    Posts
    1,312

    Re: why doesnt this work

    And what exactly You have in B2?

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

    Re: why doesnt this work

    Cybereyeball,

    Please take a moment to read the forum rules and then amend your thread title to something descriptive of your problem. Once you have done this please send me a PM and I will remove this request.

    To change a Title on your post, click EDIT then Go Advanced and change your title, if 2 days have passed ask a moderator to do it for you.
    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]

+ 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