+ Reply to Thread
Results 1 to 9 of 9

Renaming worksheet based on what is contained in one cell conteant shows a syntax error

  1. #1
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Renaming worksheet based on what is contained in one cell conteant shows a syntax error

    I have got a syntx error on the line
    Please Login or Register  to view this content.
    Could you please help?


    Please Login or Register  to view this content.

  2. #2
    Forum Expert
    Join Date
    06-25-2009
    Location
    Sofia, Bulgaria, EU
    MS-Off Ver
    Excel 2003-2013
    Posts
    1,290

    Re: Renaming worksheet based on what is contained in one cell conteant shows a syntax err

    Hi,
    The code looks fine to me. is it possible that you have also chart sheets in your workbook? However in this case it will not be a syntax error...

    Buran
    If you are pleased with a member's answer then use the Star icon to rate it.

  3. #3
    Forum Expert
    Join Date
    06-25-2009
    Location
    Sofia, Bulgaria, EU
    MS-Off Ver
    Excel 2003-2013
    Posts
    1,290

    Re: Renaming worksheet based on what is contained in one cell conteant shows a syntax err

    Also, check that you don't have empty G2 cell and that values in the G2 cells are allowed for worksheet name - there are some characters that are not allowed in the worksheet name.
    The code works fine when only worksheets in the workbook and all G2 are not empty
    Buran

  4. #4
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: Renaming worksheet based on what is contained in one cell conteant shows a syntax err

    Buran! Thanks!, No I do not have charts. Actually, I have created a new sheet with values in G2 to test it, but still shows error 1004 " Method name of object_worksheet failed

  5. #5
    Forum Expert
    Join Date
    06-25-2009
    Location
    Sofia, Bulgaria, EU
    MS-Off Ver
    Excel 2003-2013
    Posts
    1,290

    Re: Renaming worksheet based on what is contained in one cell conteant shows a syntax err

    Can you upload your sample workbook? You can find my sample workbook and your code works just fine in it.
    Attached Files Attached Files

  6. #6
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: Renaming worksheet based on what is contained in one cell conteant shows a syntax err

    Buran! Thanks!
    When I put your code in to my personal workbook modules code, I had the same error, but when I created a new sheet and put the code in to new module, it works. Very strange!

  7. #7
    Forum Expert
    Join Date
    06-25-2009
    Location
    Sofia, Bulgaria, EU
    MS-Off Ver
    Excel 2003-2013
    Posts
    1,290

    Re: Renaming worksheet based on what is contained in one cell conteant shows a syntax err

    If it is in your personal workbook, then ThisWorkbook refers to it, not the active workbook. So what you are doing is that you loop trough sheets in active workbook and for the name of first worksheet in the active workbook, you try to read g2 value from the first sheet in the personal workbook (most probably empty cell). I assume that another problem would be different number of sheets in the two workbooks

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

    Re: Renaming worksheet based on what is contained in one cell conteant shows a syntax err

    like buran said I reckon you meant
    Please Login or Register  to view this content.
    or easier
    Please Login or Register  to view this content.
    Josie

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

  9. #9
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: Renaming worksheet based on what is contained in one cell conteant shows a syntax err

    JosephP and Buran! Thanks you very much for your time and help!

    JosephP! I am glad you are becoming my mentor on this site. You included my favourite loop code as alternative.
    You are probably right! "Probably" because I am still novice to VBA and do not understand what I am doing, so will accept your arguments. What is interesting is though I had similar issued before with personal workbook modules and did not check if my code was referring to particular sheet, or active sheet, but I did not know the issue then. This shows that you never stop learning on this site.

+ 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