Home |
Search |
Today's Posts |
#1
![]() |
|||
|
|||
![]()
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. |
#2
![]() |
|||
|
|||
![]()
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. |
#3
![]() |
|||
|
|||
![]()
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. |
#4
![]() |
|||
|
|||
![]()
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. |
#5
![]() |
|||
|
|||
![]()
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. |
#6
![]() |
|||
|
|||
![]()
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. |
#7
![]() |
|||
|
|||
![]()
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. |
#8
![]() |
|||
|
|||
![]()
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. |
#9
![]()
Posted to microsoft.public.excel.misc
|
|||
|
|||
![]()
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. |
#10
![]()
Posted to microsoft.public.excel.misc
|
|||
|
|||
![]()
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. |
#11
![]()
Posted to microsoft.public.excel.misc
|
|||
|
|||
![]()
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. |
#12
![]()
Posted to microsoft.public.excel.misc
|
|||
|
|||
![]()
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 |
#13
![]()
Posted to microsoft.public.excel.misc
|
|||
|
|||
![]()
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 |
#14
![]()
Posted to microsoft.public.excel.misc
|
|||
|
|||
![]()
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 |
#15
![]()
Posted to microsoft.public.excel.misc
|
|||
|
|||
![]()
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 |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Worksheet tabs viewing there of | Excel Worksheet Functions | |||
rename worksheet | Excel Discussion (Misc queries) | |||
how do i rename worksheet to equal cell name | Excel Worksheet Functions | |||
HOW DO I DELETE A WORKSHEET IN EXCEL? NOT HIDE IT OR RENAME IT | Excel Worksheet Functions | |||
Auto color change to tabs in worksheet | Excel Worksheet Functions |