+ Reply to Thread
Results 1 to 6 of 6

Sheet Name to Cell Value

  1. #1
    Registered User
    Join Date
    05-26-2004
    Posts
    61

    Sheet Name to Cell Value

    Hi:

    have a very large workbook with about 200 sheets. Each sheet has a name. I need to copy the sheet name to cell B7 on that sheet for every sheet. Does any one has a code for this? I was tryng to use

    ActiveSheet.Range("B7").Text = ActiveSheet.Name

    but I can't get it to work.


  2. #2
    Norman Jones
    Guest

    Re: Sheet Name to Cell Value

    Hi Halem,

    Try:

    '=============>>
    Public Sub Tester()
    Dim SH As Worksheet

    For Each SH In ThisWorkbook.Worksheets
    SH.Range("B7").Value = SH.Name
    Next SH

    End Sub
    '<<=============


    ---
    Regards,
    Norman


    "halem2" <[email protected]> wrote in
    message news:[email protected]...
    >
    > Hi:
    >
    > have a very large workbook with about 200 sheets. Each sheet has a
    > name. I need to copy the sheet name to cell B7 on that sheet for every
    > sheet. Does any one has a code for this? I was tryng to use
    >
    > ActiveSheet.Range("B7").Text = ActiveSheet.Name
    >
    > but I can't get it to work.
    >
    >
    >
    >
    > --
    > halem2
    > ------------------------------------------------------------------------
    > halem2's Profile:
    > http://www.excelforum.com/member.php...fo&userid=9930
    > View this thread: http://www.excelforum.com/showthread...hreadid=556975
    >




  3. #3
    Mark Driscol
    Guest

    Re: Sheet Name to Cell Value

    Option Explicit

    Sub SheetNames()

    Dim wks As Worksheet

    For Each wks In Worksheets
    wks.Range("B7").Value = wks.Name
    Next wks

    End Sub


    Mark


    halem2 wrote:
    > Hi:
    >
    > have a very large workbook with about 200 sheets. Each sheet has a
    > name. I need to copy the sheet name to cell B7 on that sheet for every
    > sheet. Does any one has a code for this? I was tryng to use
    >
    > ActiveSheet.Range("B7").Text = ActiveSheet.Name
    >
    > but I can't get it to work.
    >
    >
    >
    >
    > --
    > halem2
    > ------------------------------------------------------------------------
    > halem2's Profile: http://www.excelforum.com/member.php...fo&userid=9930
    > View this thread: http://www.excelforum.com/showthread...hreadid=556975



  4. #4
    Jim Thomlinson
    Guest

    RE: Sheet Name to Cell Value

    Here you go...

    sub SheetNames
    dim wks as worksheet

    for each wks in worksheets
    wks.range("B7").value = wks.name
    next wks
    end sub


    --
    HTH...

    Jim Thomlinson


    "halem2" wrote:

    >
    > Hi:
    >
    > have a very large workbook with about 200 sheets. Each sheet has a
    > name. I need to copy the sheet name to cell B7 on that sheet for every
    > sheet. Does any one has a code for this? I was tryng to use
    >
    > ActiveSheet.Range("B7").Text = ActiveSheet.Name
    >
    > but I can't get it to work.
    >
    >
    >
    >
    > --
    > halem2
    > ------------------------------------------------------------------------
    > halem2's Profile: http://www.excelforum.com/member.php...fo&userid=9930
    > View this thread: http://www.excelforum.com/showthread...hreadid=556975
    >
    >


  5. #5
    Dave Peterson
    Guest

    Re: Sheet Name to Cell Value

    Option Explicit
    Sub testme()
    Dim wks As Worksheet
    For Each wks In ActiveWorkbook.Worksheets
    With wks
    .Range("B7").Value = "'" & .Name
    End With
    Next wks
    End Sub

    But if the sheets can change name, maybe a formula would be better:

    Option Explicit
    Sub testme()
    Dim wks As Worksheet
    Dim myFormula As String

    myFormula _
    = "=MID(CELL(""filename"",a1),FIND(""]"",CELL(""filename"",a1))+1,255)"

    For Each wks In ActiveWorkbook.Worksheets
    With wks
    .Range("B7").Formula = myFormula
    End With
    Next wks
    End Sub

    The formula will reevaluate when the worksheet name changes.

    (The workbook has to be saved at least once for the formula to work, though.)


    halem2 wrote:
    >
    > Hi:
    >
    > have a very large workbook with about 200 sheets. Each sheet has a
    > name. I need to copy the sheet name to cell B7 on that sheet for every
    > sheet. Does any one has a code for this? I was tryng to use
    >
    > ActiveSheet.Range("B7").Text = ActiveSheet.Name
    >
    > but I can't get it to work.
    >
    >
    >
    > --
    > halem2
    > ------------------------------------------------------------------------
    > halem2's Profile: http://www.excelforum.com/member.php...fo&userid=9930
    > View this thread: http://www.excelforum.com/showthread...hreadid=556975


    --

    Dave Peterson

  6. #6
    Registered User
    Join Date
    05-26-2004
    Posts
    61

    Talking

    worked like a charm! thanks a million.

+ 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