+ Reply to Thread
Results 1 to 7 of 7

How to fill a cell with the name of the worksheet

  1. #1
    Registered User
    Join Date
    09-16-2011
    Location
    Hong Kong
    MS-Off Ver
    Excel 2003
    Posts
    52

    How to fill a cell with the name of the worksheet

    If I want to fill A1 with "ABC" and A2 with "DEF" AND A3 with the name of the worksheet on multiple worksheets and these actions are not to be done on each worksheet (e.g. not on worksheet 1 & 2 but do it only on worksheet 3-20 or more), how can I do it with VBA?

    With reference to the post on http://www.excelforum.com/excel-new-...ary-sheet.html, I came up with the following codes. Could anyone advise? Many thanks.

    Please Login or Register  to view this content.
    Last edited by alexxgalaxy; 09-22-2011 at 12:34 AM.

  2. #2
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: How to fill a cell with the name of the tab

    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
    Hope that helps.

    RoyUK
    --------
    For Excel Tips & Solutions, free examples and tutorials why not check out my web site

    Free DataBaseForm example

  3. #3
    Forum Guru (RIP) Marcol's Avatar
    Join Date
    12-23-2009
    Location
    Fife, Scotland
    MS-Off Ver
    Excel '97 & 2003/7
    Posts
    7,216

    Re: How to fill a cell with the name of the worksheet

    Try this
    Please Login or Register  to view this content.
    Hope this helps
    If you need any more information, please feel free to ask.

    However,If this takes care of your needs, please select Thread Tools from menu above and set this topic to SOLVED. It helps everybody! ....

    Also
    اس کی مدد کرتا ہے اگر
    شکریہ کہنے کے لئے سٹار کلک کریں
    If you are satisfied by any members response to your problem please consider using the small Star icon bottom left of their post to show your appreciation.

  4. #4
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: How to fill a cell with the name of the worksheet

    Hi,

    You can of course also return the sheet name with a formula. First group all the sheets in which you want the sheet name to appear, i.e. sheets 3-20

    Enter "ABC" in A1 on any sheet, "DEF" in A2 on any sheet and
    =MID(CELL("filename",A1),FIND("]",CELL("filename",A1))+1,31)
    in A3 on any sheet.

    Then undo the grouping.

    Regards
    Richard Buttrey

    RIP - d. 06/10/2022

    If any of the responses have helped then please consider rating them by clicking the small star icon below the post.

  5. #5
    Registered User
    Join Date
    09-16-2011
    Location
    Hong Kong
    MS-Off Ver
    Excel 2003
    Posts
    52

    Re: How to fill a cell with the name of the worksheet

    Thanks Marcol ! That worked very well. I would like to add one more cell A4 and it's value changes every time, let say, it's the date. I tried to add an InputBox after Range("A3")... but when I ran the Marco, the InputBox prompted up for every worksheet (I have more than 30 worksheets @@). I'd also like to do some formatting and adjust the column width. Could you take a look at below codes and let me know if that's the way?

    And sorry, one more, what if I don't want the actions done on a few worksheets. They might not be the first two worksheets. Sometimes it might be the 21st and 29th while sometimes the others. I won't be able to tell the sequence of the worksheets because it might change every time (unless I count) but what I could be certain was the name of the worksheet.

    Please Login or Register  to view this content.
    Last edited by alexxgalaxy; 09-17-2011 at 08:40 AM.

  6. #6
    Registered User
    Join Date
    09-16-2011
    Location
    Hong Kong
    MS-Off Ver
    Excel 2003
    Posts
    52

    Re: How to fill a cell with the name of the worksheet

    Thanks Richard. That's what I did at the first place but it didn't work somehow. I did the actions recording it as Marco but when I played it afterwards, the actions were performed on only the worksheet which was activated.
    Last edited by alexxgalaxy; 09-17-2011 at 07:19 PM.

  7. #7
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: How to fill a cell with the name of the worksheet

    Hi,

    Try doing it manually and not bothering to record a macro.

    Copying the cells then Grouping the sheets and pasting works OK for me.

    Regards

+ 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