Solved

Excel 2010 Rename sheets if not called Summary

Posted on 2014-01-08
7
269 Views
Last Modified: 2014-01-08
Could someone provide me with VBA code to rename sheets Sheet1, Sheet2 etc that are not already named Summary

Thanks
0
Comment
Question by:Jagwarman
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
7 Comments
 
LVL 3

Assisted Solution

by:Sreeram
Sreeram earned 250 total points
ID: 39764870
HI Jagwarman,

Try this:

Sub Macro1()
    Dim I As Integer
        For I = 1 To Application.ActiveWorkbook.Worksheets.Count
            If Application.ActiveWorkbook.Sheets(I).Name <> "Summary" Then
                Application.ActiveWorkbook.Sheets(I).Name = "Give_Your_Sheet_Name"
            End If
        Next
           
End Sub
0
 
LVL 34

Expert Comment

by:Norie
ID: 39764874
Rename them to what?
0
 
LVL 51

Expert Comment

by:Rgonzo1971
ID: 39764933
HI,

This code preserves the sheets named Sheet1, Sheet2, etc

Sub macro()
ShIndex = 0
    For Each sh In ThisWorkbook.Worksheets
        If sh.Name <> "Summary" And Not (sh.Name Like "Sheet[1-9]") And Not (sh.Name Like "Sheet[1-9][0-9]") Then
        Do
            Set TestSheet = Nothing
            ShIndex = ShIndex + 1
            On Error Resume Next
            Set TestSheet = Sheets("Sheet" & ShIndex)
            On Error GoTo 0
        Loop While Not (TestSheet Is Nothing)
        sh.Name = "Sheet" & ShIndex
        ShIndex = 0
        End If
    Next
End Sub

Open in new window

Regards
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:Jagwarman
ID: 39765128
it must be me because I cannot get this to work
0
 

Author Comment

by:Jagwarman
ID: 39765133
Ah this has to be in the Workbook that I have opened to work.
0
 
LVL 51

Accepted Solution

by:
Rgonzo1971 earned 250 total points
ID: 39765144
pls try
Sub macro()
ShIndex = 0
    For Each sh In ActiveWorkbook.Worksheets
        If sh.Name <> "Summary" And Not (sh.Name Like "Sheet[1-9]") And Not (sh.Name Like "Sheet[1-9][0-9]") Then
        Do
            Set TestSheet = Nothing
            ShIndex = ShIndex + 1
            On Error Resume Next
            Set TestSheet = Sheets("Sheet" & ShIndex)
            On Error GoTo 0
        Loop While Not (TestSheet Is Nothing)
        sh.Name = "Sheet" & ShIndex
        ShIndex = 0
        End If
    Next
End Sub 

Open in new window

0
 

Author Closing Comment

by:Jagwarman
ID: 39765567
Thanks
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Some code to ensure data integrity when using macros within Excel. Also included code that helps secure your data within an Excel workbook.
Access developers frequently have requirements to interact with Excel (import from or output to) in their applications.  You might be able to accomplish this with the TransferSpreadsheet and OutputTo methods, but in this series of articles I will di…
This Micro Tutorial will demonstrate in Google Sheets how to use the HYPERLINK function to create live links inside your spreadsheet.
This Micro Tutorial will demonstrate how to create pivot charts out of a data set. I also added a drop-down menu which allows to choose from different categories in the data set and the chart will automatically update.

738 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question