Rename all Worksheets in File

snuffnchess

Board Regular
Joined
May 15, 2015
Messages
68
Office Version
  1. 365
Platform
  1. Windows
Original Post - Rename all Worksheets in File
Would not allow me to post a response - getting an HTTP ERROR 500 - so creating a new post. - Nimrod1313 I hope you see this, and do not think I am being rude by not responding.


The updated code is great and does what it is supposed to do. However there are just TOO many tabs that are formatted too poorly for it to work effectively. So I am ending up needing to manually edit a large portion of the worksheet names.

I have a work around though... but need optimizing help.

I use the following to generate a listing of the WS Names

Code:
Sub ListWSNames()

Dim ob As Workbook
    Dim ws As Worksheet
    
    Set ob = ActiveWorkbook
    Set ws = Sheets.Add(Before:=Sheets(1))
    ws.Name = "Index"



    For i = 1 To ob.Sheets.Count
        ws.Cells(i, 1) = i
        ws.Cells(i, 2) = ob.Sheets(i).Name
    Next i

    With ws
         .Rows(1).Insert
         .Cells(1, 1) = "Index"
         .Cells(1, 2) = "Original"
         .Cells(1, 3) = "Updated"
         .Columns("A:C").AutoFit
         .Rows(2).Delete
    End With
End Sub

And then the following to update the WS names.

Code:
Sub replacews()
Dim ws As Worksheet
Dim owb As Workbook
Dim ows As Worksheet
Dim owslr As Long

Dim i As Long

Application.ScreenUpdating = False
Application.DisplayAlerts = False

Set owb = ThisWorkbook
Set ows = owb.Sheets("Index")


owslr = Cells(Rows.Count, "A").End(xlUp).Row + 1




For i = 2 To owslr
    For Each ws In Worksheets
        If ws.Name, ows.Range("B" & i).Value Then ws.Name = Format(ows.Range("C" & i).Value, "yyyy-mm-dd")
            Columns.AutoFit
        End If
    Next ws
Next i

Application.ScreenUpdating = True
Application.DisplayAlerts = True

End Sub

Code works fine if there is a small number of sheets... but when dealing with 100 (and sometimes 150 different sheets, it is just sifting through EVERY worksheet non stop. I am sure there is a better way to do this... and one that would take less resources to do.

your thoughts???
 

Excel Facts

Excel motto
Not everything I do at work revolves around Excel. Only the fun parts.
Please try this


VBA Code:
Sub replacews()
  
  Dim ws As Worksheet
  Dim owb As Workbook
  Dim ows As Worksheet
  Dim Rng As Range
  Dim Cel As Range
  
  
  
  Application.ScreenUpdating = False
  Application.DisplayAlerts = False
  Application.Calculation = xlCalculationManual
  
  Set owb = ThisWorkbook
  Set ows = owb.Sheets("Index")
  
  
  Set Cel = ows.Range("A2")
  Set Rng = ows.Range(Cel, Cel.Offset(10000, 0).End(xlUp))
  
  On Error Resume Next
  For Each Cel In Rng
    If Cel.Offset(0, 1).Value <> "Index" Then
      Set ws = Sheets(Cel.Offset(0, 1).Value)
      If Not ws Is Nothing Then
        ws.Name = Format(Cel.Offset(0, 2).Value, "yyyy-mm-dd")
        ws.Columns.AutoFit
      End If
    End If
  Next Cel
  On Error GoTo 0
    
    
  Application.Calculation = xlCalculationAutomatic
  Application.ScreenUpdating = True
  Application.DisplayAlerts = True

End Sub
 
Upvote 0
Would not allow me to post a response - getting an HTTP ERROR 500 - so creating a new post. - Nimrod1313 I hope you see this, and do not think I am being rude by not responding.
How would Nimrod1313 see this, as it's a totally different site?
 
Upvote 0

Forum statistics

Threads
1,214,911
Messages
6,122,194
Members
449,072
Latest member
DW Draft

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top