ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Discussion (Misc queries) (https://www.excelbanter.com/excel-discussion-misc-queries/)
-   -   Rename all existing worksheet tabs (https://www.excelbanter.com/excel-discussion-misc-queries/40926-rename-all-existing-worksheet-tabs.html)

MikeM

Rename all existing worksheet tabs
 
I would like to take an existing workbook and rename all the worksheet tabs
at one time. For example, I might have ten worksheets with various names and
I'd like them all to be named USA1, USA2, USA3 and so on.

Can this be easily done with some VBA code? (I've seen some similar
questions, but none exactly like this one.)

Thanks.

Bob Phillips

Const sBase as string = "USA"
Dim i as long
Dim sh As Object

For Each sh In Activeworkbook.Sheets
i = i + 1
sh.name = sBase & i
Next sh

--

HTH

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


"MikeM" <michael[dot]mittelmanl[at]db[dot]com wrote in message
...
I would like to take an existing workbook and rename all the worksheet

tabs
at one time. For example, I might have ten worksheets with various names

and
I'd like them all to be named USA1, USA2, USA3 and so on.

Can this be easily done with some VBA code? (I've seen some similar
questions, but none exactly like this one.)

Thanks.




MikeM

Bob:
Thanks so much for your quick reply! I tried it and it works perfectly.

Could it be set up so I could define the worksheet name before running the
macro? (by typing it into a cell or something like that)?

For example, one workbook might need to be USA1, USA2, etc. and another
might need to be CANADA1, CANADA2, etc.

"Bob Phillips" wrote:

Const sBase as string = "USA"
Dim i as long
Dim sh As Object

For Each sh In Activeworkbook.Sheets
i = i + 1
sh.name = sBase & i
Next sh

--

HTH

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


"MikeM" <michael[dot]mittelmanl[at]db[dot]com wrote in message
...
I would like to take an existing workbook and rename all the worksheet

tabs
at one time. For example, I might have ten worksheets with various names

and
I'd like them all to be named USA1, USA2, USA3 and so on.

Can this be easily done with some VBA code? (I've seen some similar
questions, but none exactly like this one.)

Thanks.





Bob Phillips

Mike,

This will get it from A1 on Sheet1, change to suit

Dim sBase as string
Dim i as long
Dim sh As Object

sBase = Worksheets("Sheet1").Range("A1").Value
For Each sh In Activeworkbook.Sheets
i = i + 1
sh.name = sBase & i
Next sh



--

HTH

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


"MikeM" <michael[dot]mittelmanl[at]db[dot]com wrote in message
...
Bob:
Thanks so much for your quick reply! I tried it and it works perfectly.

Could it be set up so I could define the worksheet name before running the
macro? (by typing it into a cell or something like that)?

For example, one workbook might need to be USA1, USA2, etc. and another
might need to be CANADA1, CANADA2, etc.

"Bob Phillips" wrote:

Const sBase as string = "USA"
Dim i as long
Dim sh As Object

For Each sh In Activeworkbook.Sheets
i = i + 1
sh.name = sBase & i
Next sh

--

HTH

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


"MikeM" <michael[dot]mittelmanl[at]db[dot]com wrote in message
...
I would like to take an existing workbook and rename all the worksheet

tabs
at one time. For example, I might have ten worksheets with various

names
and
I'd like them all to be named USA1, USA2, USA3 and so on.

Can this be easily done with some VBA code? (I've seen some similar
questions, but none exactly like this one.)

Thanks.







David McRitchie

Or more likely set up the prefix with an InputBox

sBase = Application.InputBox("Supply Prefix for worksheet renaming", _
"Rename worksheets", "USA")
If sBase = "" Then
MsgBox "Cancelled by your command"
exit sub
end if

---
HTH,
David McRitchie, Microsoft MVP - Excel [site changed Nov. 2001]
My Excel Pages: http://www.mvps.org/dmcritchie/excel/excel.htm
Search Page: http://www.mvps.org/dmcritchie/excel/search.htm

"Bob Phillips" wrote in message ...
Mike,

This will get it from A1 on Sheet1, change to suit

Dim sBase as string
Dim i as long
Dim sh As Object

sBase = Worksheets("Sheet1").Range("A1").Value
For Each sh In Activeworkbook.Sheets
i = i + 1
sh.name = sBase & i
Next sh



--

HTH

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


"MikeM" <michael[dot]mittelmanl[at]db[dot]com wrote in message
...
Bob:
Thanks so much for your quick reply! I tried it and it works perfectly.

Could it be set up so I could define the worksheet name before running the
macro? (by typing it into a cell or something like that)?

For example, one workbook might need to be USA1, USA2, etc. and another
might need to be CANADA1, CANADA2, etc.

"Bob Phillips" wrote:

Const sBase as string = "USA"
Dim i as long
Dim sh As Object

For Each sh In Activeworkbook.Sheets
i = i + 1
sh.name = sBase & i
Next sh

--

HTH

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


"MikeM" <michael[dot]mittelmanl[at]db[dot]com wrote in message
...
I would like to take an existing workbook and rename all the worksheet
tabs
at one time. For example, I might have ten worksheets with various

names
and
I'd like them all to be named USA1, USA2, USA3 and so on.

Can this be easily done with some VBA code? (I've seen some similar
questions, but none exactly like this one.)

Thanks.








Bob Phillips

Don't like InputBox Dave, would much rather type in a cell. Too easy to make
a mistake, maybe not with USA, but easy with Kazakhstan.

--

HTH

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


"David McRitchie" wrote in message
...
Or more likely set up the prefix with an InputBox

sBase = Application.InputBox("Supply Prefix for worksheet renaming",

_
"Rename worksheets", "USA")
If sBase = "" Then
MsgBox "Cancelled by your command"
exit sub
end if

---
HTH,
David McRitchie, Microsoft MVP - Excel [site changed Nov. 2001]
My Excel Pages: http://www.mvps.org/dmcritchie/excel/excel.htm
Search Page: http://www.mvps.org/dmcritchie/excel/search.htm

"Bob Phillips" wrote in message

...
Mike,

This will get it from A1 on Sheet1, change to suit

Dim sBase as string
Dim i as long
Dim sh As Object

sBase = Worksheets("Sheet1").Range("A1").Value
For Each sh In Activeworkbook.Sheets
i = i + 1
sh.name = sBase & i
Next sh



--

HTH

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


"MikeM" <michael[dot]mittelmanl[at]db[dot]com wrote in message
...
Bob:
Thanks so much for your quick reply! I tried it and it works

perfectly.

Could it be set up so I could define the worksheet name before running

the
macro? (by typing it into a cell or something like that)?

For example, one workbook might need to be USA1, USA2, etc. and

another
might need to be CANADA1, CANADA2, etc.

"Bob Phillips" wrote:

Const sBase as string = "USA"
Dim i as long
Dim sh As Object

For Each sh In Activeworkbook.Sheets
i = i + 1
sh.name = sBase & i
Next sh

--

HTH

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


"MikeM" <michael[dot]mittelmanl[at]db[dot]com wrote in message
...
I would like to take an existing workbook and rename all the

worksheet
tabs
at one time. For example, I might have ten worksheets with

various
names
and
I'd like them all to be named USA1, USA2, USA3 and so on.

Can this be easily done with some VBA code? (I've seen some

similar
questions, but none exactly like this one.)

Thanks.










MikeM

Many thanks to you Bob, and David as well for such quick and informative
responses. This is the first time I've posted a question here and will
certainly continue to do so in the future!
Mike

"Bob Phillips" wrote:

Don't like InputBox Dave, would much rather type in a cell. Too easy to make
a mistake, maybe not with USA, but easy with Kazakhstan.

--

HTH

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


"David McRitchie" wrote in message
...
Or more likely set up the prefix with an InputBox

sBase = Application.InputBox("Supply Prefix for worksheet renaming",

_
"Rename worksheets", "USA")
If sBase = "" Then
MsgBox "Cancelled by your command"
exit sub
end if

---
HTH,
David McRitchie, Microsoft MVP - Excel [site changed Nov. 2001]
My Excel Pages: http://www.mvps.org/dmcritchie/excel/excel.htm
Search Page: http://www.mvps.org/dmcritchie/excel/search.htm

"Bob Phillips" wrote in message

...
Mike,

This will get it from A1 on Sheet1, change to suit

Dim sBase as string
Dim i as long
Dim sh As Object

sBase = Worksheets("Sheet1").Range("A1").Value
For Each sh In Activeworkbook.Sheets
i = i + 1
sh.name = sBase & i
Next sh



--

HTH

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


"MikeM" <michael[dot]mittelmanl[at]db[dot]com wrote in message
...
Bob:
Thanks so much for your quick reply! I tried it and it works

perfectly.

Could it be set up so I could define the worksheet name before running

the
macro? (by typing it into a cell or something like that)?

For example, one workbook might need to be USA1, USA2, etc. and

another
might need to be CANADA1, CANADA2, etc.

"Bob Phillips" wrote:

Const sBase as string = "USA"
Dim i as long
Dim sh As Object

For Each sh In Activeworkbook.Sheets
i = i + 1
sh.name = sBase & i
Next sh

--

HTH

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


"MikeM" <michael[dot]mittelmanl[at]db[dot]com wrote in message
...
I would like to take an existing workbook and rename all the

worksheet
tabs
at one time. For example, I might have ten worksheets with

various
names
and
I'd like them all to be named USA1, USA2, USA3 and so on.

Can this be easily done with some VBA code? (I've seen some

similar
questions, but none exactly like this one.)

Thanks.











MikeM

David:
I tried this solution and it works nicely as well. Many thanks!
Mike

"David McRitchie" wrote:

Or more likely set up the prefix with an InputBox

sBase = Application.InputBox("Supply Prefix for worksheet renaming", _
"Rename worksheets", "USA")
If sBase = "" Then
MsgBox "Cancelled by your command"
exit sub
end if

---
HTH,
David McRitchie, Microsoft MVP - Excel [site changed Nov. 2001]
My Excel Pages: http://www.mvps.org/dmcritchie/excel/excel.htm
Search Page: http://www.mvps.org/dmcritchie/excel/search.htm

"Bob Phillips" wrote in message ...
Mike,

This will get it from A1 on Sheet1, change to suit

Dim sBase as string
Dim i as long
Dim sh As Object

sBase = Worksheets("Sheet1").Range("A1").Value
For Each sh In Activeworkbook.Sheets
i = i + 1
sh.name = sBase & i
Next sh



--

HTH

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


"MikeM" <michael[dot]mittelmanl[at]db[dot]com wrote in message
...
Bob:
Thanks so much for your quick reply! I tried it and it works perfectly.

Could it be set up so I could define the worksheet name before running the
macro? (by typing it into a cell or something like that)?

For example, one workbook might need to be USA1, USA2, etc. and another
might need to be CANADA1, CANADA2, etc.

"Bob Phillips" wrote:

Const sBase as string = "USA"
Dim i as long
Dim sh As Object

For Each sh In Activeworkbook.Sheets
i = i + 1
sh.name = sBase & i
Next sh

--

HTH

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


"MikeM" <michael[dot]mittelmanl[at]db[dot]com wrote in message
...
I would like to take an existing workbook and rename all the worksheet
tabs
at one time. For example, I might have ten worksheets with various

names
and
I'd like them all to be named USA1, USA2, USA3 and so on.

Can this be easily done with some VBA code? (I've seen some similar
questions, but none exactly like this one.)

Thanks.









dford

Rename all existing worksheet tabs
 
I would like to rename just selected worksheets. Could a modification of this
code be possible?

"Bob Phillips" wrote:

Const sBase as string = "USA"
Dim i as long
Dim sh As Object

For Each sh In Activeworkbook.Sheets
i = i + 1
sh.name = sBase & i
Next sh

--

HTH

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


"MikeM" <michael[dot]mittelmanl[at]db[dot]com wrote in message
...
I would like to take an existing workbook and rename all the worksheet

tabs
at one time. For example, I might have ten worksheets with various names

and
I'd like them all to be named USA1, USA2, USA3 and so on.

Can this be easily done with some VBA code? (I've seen some similar
questions, but none exactly like this one.)

Thanks.





Bob Phillips

Rename all existing worksheet tabs
 
Const sBase As String = "USA"
Dim i As Long
Dim sh As Object

For Each sh In ActiveWorkbook.Windows(1).SelectedSheets
i = i + 1
sh.Name = sBase & i
Next sh

--
HTH

Bob Phillips

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

"dford" wrote in message
...
I would like to rename just selected worksheets. Could a modification of

this
code be possible?

"Bob Phillips" wrote:

Const sBase as string = "USA"
Dim i as long
Dim sh As Object

For Each sh In Activeworkbook.Sheets
i = i + 1
sh.name = sBase & i
Next sh

--

HTH

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


"MikeM" <michael[dot]mittelmanl[at]db[dot]com wrote in message
...
I would like to take an existing workbook and rename all the worksheet

tabs
at one time. For example, I might have ten worksheets with various

names
and
I'd like them all to be named USA1, USA2, USA3 and so on.

Can this be easily done with some VBA code? (I've seen some similar
questions, but none exactly like this one.)

Thanks.







rizello

Rename all existing worksheet tabs
 
Hello:

I would like to do this also. Is it possible to do without using VBA, but
simply a command in Excel?

"MikeM" wrote:

I would like to take an existing workbook and rename all the worksheet tabs
at one time. For example, I might have ten worksheets with various names and
I'd like them all to be named USA1, USA2, USA3 and so on.

Can this be easily done with some VBA code? (I've seen some similar
questions, but none exactly like this one.)

Thanks.


Dave Peterson

Rename all existing worksheet tabs
 
There's not in Excel's user interface that would allow you do to lots of renames
all at once. You'd need a macro or do it manually (over and over).

rizello wrote:

Hello:

I would like to do this also. Is it possible to do without using VBA, but
simply a command in Excel?

"MikeM" wrote:

I would like to take an existing workbook and rename all the worksheet tabs
at one time. For example, I might have ten worksheets with various names and
I'd like them all to be named USA1, USA2, USA3 and so on.

Can this be easily done with some VBA code? (I've seen some similar
questions, but none exactly like this one.)

Thanks.


--

Dave Peterson

Wally

Rename all existing worksheet tabs
 
I have a similar need, but wish to rename the tabs by referencing the same
cell on each worksheet that contains an invoice number.

"Dave Peterson" wrote:

There's not in Excel's user interface that would allow you do to lots of renames
all at once. You'd need a macro or do it manually (over and over).

rizello wrote:

Hello:

I would like to do this also. Is it possible to do without using VBA, but
simply a command in Excel?

"MikeM" wrote:

I would like to take an existing workbook and rename all the worksheet tabs
at one time. For example, I might have ten worksheets with various names and
I'd like them all to be named USA1, USA2, USA3 and so on.

Can this be easily done with some VBA code? (I've seen some similar
questions, but none exactly like this one.)

Thanks.


--

Dave Peterson


Dave Peterson

Rename all existing worksheet tabs
 
One way:

Option Explicit
Sub testme01()
Dim wks As Worksheet
For Each wks In ActiveWorkbook.Worksheets
With wks
On Error Resume Next
.Name = .Range("a1").Text
If Err.Number < 0 Then
MsgBox .Name & " was not renamed"
Err.Clear
End If
On Error GoTo 0
End With
Next wks
End Sub

Wally wrote:

I have a similar need, but wish to rename the tabs by referencing the same
cell on each worksheet that contains an invoice number.

"Dave Peterson" wrote:

There's not in Excel's user interface that would allow you do to lots of renames
all at once. You'd need a macro or do it manually (over and over).

rizello wrote:

Hello:

I would like to do this also. Is it possible to do without using VBA, but
simply a command in Excel?

"MikeM" wrote:

I would like to take an existing workbook and rename all the worksheet tabs
at one time. For example, I might have ten worksheets with various names and
I'd like them all to be named USA1, USA2, USA3 and so on.

Can this be easily done with some VBA code? (I've seen some similar
questions, but none exactly like this one.)

Thanks.


--

Dave Peterson


--

Dave Peterson

Wally

Rename all existing worksheet tabs
 
WOW! It's magic. Thank You Dave

"Dave Peterson" wrote:

One way:

Option Explicit
Sub testme01()
Dim wks As Worksheet
For Each wks In ActiveWorkbook.Worksheets
With wks
On Error Resume Next
.Name = .Range("a1").Text
If Err.Number < 0 Then
MsgBox .Name & " was not renamed"
Err.Clear
End If
On Error GoTo 0
End With
Next wks
End Sub

Wally wrote:

I have a similar need, but wish to rename the tabs by referencing the same
cell on each worksheet that contains an invoice number.

"Dave Peterson" wrote:

There's not in Excel's user interface that would allow you do to lots of renames
all at once. You'd need a macro or do it manually (over and over).

rizello wrote:

Hello:

I would like to do this also. Is it possible to do without using VBA, but
simply a command in Excel?

"MikeM" wrote:

I would like to take an existing workbook and rename all the worksheet tabs
at one time. For example, I might have ten worksheets with various names and
I'd like them all to be named USA1, USA2, USA3 and so on.

Can this be easily done with some VBA code? (I've seen some similar
questions, but none exactly like this one.)

Thanks.

--

Dave Peterson


--

Dave Peterson



All times are GMT +1. The time now is 04:13 PM.

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