Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default 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.




--
halem2
------------------------------------------------------------------------
halem2's Profile: http://www.excelforum.com/member.php...fo&userid=9930
View this thread: http://www.excelforum.com/showthread...hreadid=556975

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,302
Default 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" wrote in
message ...

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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 75
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,939
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Sheet Name to Cell Value


worked like a charm! thanks a million.
:) :) ;) ;)


--
halem2
------------------------------------------------------------------------
halem2's Profile: http://www.excelforum.com/member.php...fo&userid=9930
View this thread: http://www.excelforum.com/showthread...hreadid=556975

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
copy rows from one Data sheet to another sheet based on cell conte John McKeon Excel Discussion (Misc queries) 2 May 15th 10 06:49 AM
How do I copying data from a cell on sheet to a diff cell/sheet Bowldiva120 Excel Worksheet Functions 1 March 21st 10 11:25 PM
copy a sum in cell on sheet 1 (not formula) to cell on sheet 2 John Excel Worksheet Functions 1 March 2nd 09 12:01 AM
copy a sum in cell on sheet 1 (not formula) to cell on sheet 2 Eduardo Excel Worksheet Functions 0 February 27th 09 05:19 PM
Excell:Move from any Cell Sheet 1 to any cell Sheet 2 etc. eldo Excel Worksheet Functions 1 August 16th 05 09:17 AM


All times are GMT +1. The time now is 09:39 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"