ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   New Users to Excel (https://www.excelbanter.com/new-users-excel/)
-   -   How to use VBA to name sheet ? (https://www.excelbanter.com/new-users-excel/100946-how-use-vba-name-sheet.html)

vumian

How to use VBA to name sheet ?
 

I have a file that i do not know how many sheet are there in before

i need to copy contain of C4 to name of sheets

Thank for your help.


--
vumian
------------------------------------------------------------------------
vumian's Profile: http://www.excelforum.com/member.php...o&userid=36494
View this thread: http://www.excelforum.com/showthread...hreadid=564347


Bob Phillips

How to use VBA to name sheet ?
 

For Each sh In Activeworkbook.Worksheets

sh.Name = sh.Range("C4").Value

Next sh

--
HTH

Bob Phillips

(replace somewhere in email address with gmail if mailing direct)

"vumian" wrote in
message ...

I have a file that i do not know how many sheet are there in before

i need to copy contain of C4 to name of sheets

Thank for your help.


--
vumian
------------------------------------------------------------------------
vumian's Profile:

http://www.excelforum.com/member.php...o&userid=36494
View this thread: http://www.excelforum.com/showthread...hreadid=564347




vumian

How to use VBA to name sheet ?
 

hi,

sorry, i fail to understand your mean

Could you be more specific,pls

Thank you.


--
vumian
------------------------------------------------------------------------
vumian's Profile: http://www.excelforum.com/member.php...o&userid=36494
View this thread: http://www.excelforum.com/showthread...hreadid=564347


SteveW

How to use VBA to name sheet ?
 
Create and run that macro.

Will do the job.

Unless you left something out of the original query.

Steve



On Tue, 25 Jul 2006 16:02:59 +0100, vumian
wrote:


hi,

sorry, i fail to understand your mean

Could you be more specific,pls

Thank you.


vumian

How to use VBA to name sheet ?
 

thanks your idea, but here can not create macro coz i do not know how
many sheet before ?

How to use For statement here ?
VBA only.

thanks for your help.


--
vumian
------------------------------------------------------------------------
vumian's Profile: http://www.excelforum.com/member.php...o&userid=36494
View this thread: http://www.excelforum.com/showthread...hreadid=564347


SteveW

How to use VBA to name sheet ?
 
Why VBA only,

Anyway I count Excel macros as VBA

"For Each sh In Activeworkbook.Worksheets"

That does the counting for you.


On Tue, 25 Jul 2006 16:19:26 +0100, vumian
wrote:


thanks your idea, but here can not create macro coz i do not know how
many sheet before ?

How to use For statement here ?
VBA only.

thanks for your help.



vumian

How to use VBA to name sheet ?
 

Dim sh As Worksheets
Sub GetName()
For Each sh In ActiveWorkbook.Worksheets
sh.Name = sh.Range("C4").Value
Next sh
End Sub


It do not run.
Why, help me pls


--
vumian
------------------------------------------------------------------------
vumian's Profile: http://www.excelforum.com/member.php...o&userid=36494
View this thread: http://www.excelforum.com/showthread...hreadid=564347


SteveW

How to use VBA to name sheet ?
 
Works perfectly without the Dim statment - not needed

Steve

On Tue, 25 Jul 2006 16:57:09 +0100, vumian
wrote:


Dim sh As Worksheets
Sub GetName()
For Each sh In ActiveWorkbook.Worksheets
sh.Name = sh.Range("C4").Value
Next sh
End Sub


It do not run.
Why, help me pls





--
Steve (3)

vumian

How to use VBA to name sheet ?
 

thank you very much, so great. man :)


--
vumian
------------------------------------------------------------------------
vumian's Profile: http://www.excelforum.com/member.php...o&userid=36494
View this thread: http://www.excelforum.com/showthread...hreadid=564347


Bob Phillips

How to use VBA to name sheet ?
 
I would advise against suggesting that variables are not declared, poor
programming practice. The problem is that it should be declared as Worksheet
against Worksheets, not that it shouldn't be declared.

--
HTH

Bob Phillips

(replace somewhere in email address with gmail if mailing direct)

"SteveW" wrote in message
news:op.tc88mtjcevjsnp@enigma03...
Works perfectly without the Dim statment - not needed

Steve

On Tue, 25 Jul 2006 16:57:09 +0100, vumian
wrote:


Dim sh As Worksheets
Sub GetName()
For Each sh In ActiveWorkbook.Worksheets
sh.Name = sh.Range("C4").Value
Next sh
End Sub


It do not run.
Why, help me pls





--
Steve (3)



SteveW

How to use VBA to name sheet ?
 
Quite right Bob,

Just the end of a long line of replies :)

On Wed, 26 Jul 2006 09:19:39 +0100, Bob Phillips
wrote:

I would advise against suggesting that variables are not declared, poor
programming practice. The problem is that it should be declared as
Worksheet
against Worksheets, not that it shouldn't be declared.




--
Steve (3)

vumian

How to use VBA to name sheet ?
 

hi everyone,

with code above, there is a error as following:

if value of C4 of every sheet same, it can not run code above.

how to msgbox in case

Sub GetName()
For Each sh In ActiveWorkbook.Worksheets
sh.Name =3D sh.Range("C4").Value
if .... What is it here to msgbox, pls
Next sh
End Sub


--
vumian
------------------------------------------------------------------------
vumian's Profile: http://www.excelforum.com/member.php...o&userid=36494
View this thread: http://www.excelforum.com/showthread...hreadid=564347



All times are GMT +1. The time now is 07:01 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com