Solved

Excel 2010 Rename sheets if not called Summary

Posted on 2014-01-08
7
237 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
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 33

Expert Comment

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

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
Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

 

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 48

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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

A little background as to how I came to I design this code: Around 5 years ago I designed an add-in that formatted Excel files to a corporate standard, applying different cell colours and font type depending on whether the cells contained inputs,…
Improved? Move/Copy Add-in Replacement - How to avoid the annoying, “A formula or sheet you want to move or copy contains the name XXX, which already exists on the destination worksheet.” David Miller (dlmille)  It was one of those days… I wa…
The viewer will learn how to simulate a series of coin tosses with the rand() function and learn how to make these “tosses” depend on a predetermined probability. Flipping Coins in Excel: Enter =RAND() into cell A2: Recalculate the random variable…
This Micro Tutorial demonstrate the bugs in Microsoft Excel for Mac with Pivot Charts.

760 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now