Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default VBA to place sheet name in cell


I am using a formula:
“Sheet "& MID(CELL("filename",B11),FIND("]",CELL("filename",B11))+2
LEN(CELL("filename",B11))-FIND("]",CELL("filename",B11))) “

to place part of the worksheet name in a cell. However because o
formatting requirements I cannot use a formula. Can I do this usin
VBA? Then I could have the macro run each time the workbook is close
to keep the cell up to date.

Thanks
Rober

--
Hammer_75
-----------------------------------------------------------------------
Hammer_757's Profile: http://www.excelforum.com/member.php...nfo&userid=741
View this thread: http://www.excelforum.com/showthread.php?threadid=40003

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default VBA to place sheet name in cell

You could use the BeforeSave event

See Chip Pearson's page on events
http://www.cpearson.com/excel/events.htm

worksheets(1).Range("B2').Value = "Sheet " & worksheets(1).Name

--
Regards,
Tom Ogilvy


"Hammer_757" wrote
in message ...

I am using a formula:
"Sheet "& MID(CELL("filename",B11),FIND("]",CELL("filename",B11))+2,
LEN(CELL("filename",B11))-FIND("]",CELL("filename",B11))) "

to place part of the worksheet name in a cell. However because of
formatting requirements I cannot use a formula. Can I do this using
VBA? Then I could have the macro run each time the workbook is closed
to keep the cell up to date.

Thanks
Robert


--
Hammer_757
------------------------------------------------------------------------
Hammer_757's Profile:

http://www.excelforum.com/member.php...fo&userid=7413
View this thread: http://www.excelforum.com/showthread...hreadid=400037



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default VBA to place sheet name in cell


Thanks tom, that was too simple to be true


--
Hammer_757
------------------------------------------------------------------------
Hammer_757's Profile: http://www.excelforum.com/member.php...fo&userid=7413
View this thread: http://www.excelforum.com/showthread...hreadid=400037

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default VBA to place sheet name in cell

What formatting requirements would stop a formula?

--

HTH

RP
(remove nothere from the email address if mailing direct)


"Hammer_757" wrote
in message ...

I am using a formula:
"Sheet "& MID(CELL("filename",B11),FIND("]",CELL("filename",B11))+2,
LEN(CELL("filename",B11))-FIND("]",CELL("filename",B11))) "

to place part of the worksheet name in a cell. However because of
formatting requirements I cannot use a formula. Can I do this using
VBA? Then I could have the macro run each time the workbook is closed
to keep the cell up to date.

Thanks
Robert


--
Hammer_757
------------------------------------------------------------------------
Hammer_757's Profile:

http://www.excelforum.com/member.php...fo&userid=7413
View this thread: http://www.excelforum.com/showthread...hreadid=400037



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default VBA to place sheet name in cell


Multiple fonts, check this post
'Multiple fonts in one cell
(http://www.excelforum.com/showthread.php?t=399469

--
Hammer_75
-----------------------------------------------------------------------
Hammer_757's Profile: http://www.excelforum.com/member.php...nfo&userid=741
View this thread: http://www.excelforum.com/showthread.php?threadid=40003



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default VBA to place sheet name in cell


I spoke too soon :(

Starting with Tom's sugestion, I came up with the following which work
fine as long as I am on the first worksheet:

Sub SheetNumberUpdate()

'Updates sheet number cell to match sheet (tab) name

ActiveSheet.Range("E54").Font.Bold = False
'clears cell formating

ActiveSheet.Range("E54").Value = "Sheet " & ActiveSheet.Name
'copies worksheetname to cell "Sheet #####"

ActiveSheet.Range("E54").Characters(1, 5).Font.Bold = True
'sets the word "Sheet" to bold font

End Sub

However, when I use it on one of the other worksheets, say sheet 5 o
6, the cell is updated with the sheet name from the first worksheet.
thought by using Activesheet. Range and Activesheet.name and making sur
the desired sheet is active this would work. what am I missing

--
Hammer_75
-----------------------------------------------------------------------
Hammer_757's Profile: http://www.excelforum.com/member.php...nfo&userid=741
View this thread: http://www.excelforum.com/showthread.php?threadid=40003

  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default VBA to place sheet name in cell

the code worked fine for me when used on any sheet that was active.

Produced the correct name.

--
Regards,
Tom Ogilvy

"Hammer_757" wrote
in message ...

I spoke too soon :(

Starting with Tom's sugestion, I came up with the following which works
fine as long as I am on the first worksheet:

Sub SheetNumberUpdate()

'Updates sheet number cell to match sheet (tab) name

ActiveSheet.Range("E54").Font.Bold = False
'clears cell formating

ActiveSheet.Range("E54").Value = "Sheet " & ActiveSheet.Name
'copies worksheetname to cell "Sheet #####"

ActiveSheet.Range("E54").Characters(1, 5).Font.Bold = True
'sets the word "Sheet" to bold font

End Sub

However, when I use it on one of the other worksheets, say sheet 5 or
6, the cell is updated with the sheet name from the first worksheet. I
thought by using Activesheet. Range and Activesheet.name and making sure
the desired sheet is active this would work. what am I missing?


--
Hammer_757
------------------------------------------------------------------------
Hammer_757's Profile:

http://www.excelforum.com/member.php...fo&userid=7413
View this thread: http://www.excelforum.com/showthread...hreadid=400037



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
Use a range value in place of sheet name John Wilson Excel Discussion (Misc queries) 1 February 26th 08 08:46 AM
Automatically place text in one cell into cell in another sheet Jack Frost New Users to Excel 2 April 13th 07 03:11 AM
how do I place the sheet tab name in my spreadsheet by formula? DRHannay Excel Worksheet Functions 3 August 2nd 06 04:44 PM
Is there a formula that will place the sheet name in a cell? Reed Excel Worksheet Functions 7 January 20th 05 01:29 AM
How do i place a graphic BEHIND an excel sheet? DangerMouse114[_4_] Excel Programming 4 May 25th 04 08:48 AM


All times are GMT +1. The time now is 02:23 PM.

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

About Us

"It's about Microsoft Excel"