Solved

Excel 2010 Rename sheets if not called Summary

Posted on 2014-01-08
7
271 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
Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

 

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

Technology Partners: 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!

Question has a verified solution.

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

How to quickly and accurately populate Word documents with Excel data, charts and images (including Automated Bookmark generation) David Miller (dlmille) Synopsis In this article you’ll learn how to use ExcelToWord! to copy data,charts, shapes …
This article describes a serious pitfall that can happen when deleting shapes using VBA.
This Micro Tutorial will demonstrate how to use longer labels with horizontal bar charts instead of the vertical column chart.
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

726 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