Change tab name - delete 3 characters

TorrO

Board Regular
Joined
Feb 13, 2003
Messages
118
Office Version
  1. 2013
Platform
  1. Windows
Hi


I have a excel sheet with tabs named (short weekday in norwegian-date) like:
M-1.1
T-2.1
O-3.1
To-4.1
F-5.1
etc to:
To-31.12

Is there a easy way to remove the letters and the hyphen so result will be:
1.1
2.1
3.1
4.1
5.1
 

Excel Facts

Can Excel fill bagel flavors?
You can teach Excel a new custom list. Type the list in cells, File, Options, Advanced, Edit Custom Lists, Import, OK
Loop through your sheets and hit them with this..

Code:
ActiveSheet.Name = Mid(ActiveSheet.Name, InStr(1, ActiveSheet.Name, "-") + 1, Len(ActiveSheet.Name) - InStr(1, ActiveSheet.Name, "-"))

Edited to Add. If you weren't sure on the looping bit..

Code:
Sub test()


Dim ws As Worksheet
For Each ws In ActiveWorkbook.Worksheets
With ws
.Activate
ActiveSheet.Name = Mid(ActiveSheet.Name, InStr(1, ActiveSheet.Name, "-") + 1, Len(ActiveSheet.Name) - InStr(1, ActiveSheet.Name, "-"))
End With
Next


End Sub
 
Last edited:
Upvote 0
Just another option:

Code:
Sub M()
Dim ws As Worksheet
For Each ws In ThisWorkbook.Worksheets
    ws.Name = Split(ws.Name, "-")(1)
Next ws
End Sub
 
Upvote 0
No worries. There's probably a slightly more efficient way of doing it, but that works well enough for me!
 
Upvote 0
Just another option:

Code:
Sub M()
Dim ws As Worksheet
For Each ws In ThisWorkbook.Worksheets
    ws.Name = Split(ws.Name, "-")(1)
Next ws
End Sub

I like that! I'll be copying that one to my bible if you don't mind..
 
Upvote 0
TorrO,

Here is another macro solution for you to consider that checks each worksheet name to see if it contains the single - character.

Please TEST this FIRST in a COPY of your workbook (always make a backup copy before trying new code, you never know what you might lose).

Code:
Sub ChangeSheetNames()
' hiker95, 06/08/2015, ME859891
Dim ws As Worksheet
Application.ScreenUpdating = False
For Each ws In ThisWorkbook.Worksheets
  If InStr(ws.Name, "-") Then
    ws.Name = Split(ws.Name, "-")(1)
  End If
Next ws
End Sub

Before you use the macro with Excel 2007 or newer, save your workbook, Save As, a macro enabled workbook with the file extension .xlsm, and, answer the "do you want to enable macros" question as "yes" or "OK" (depending on the button label for your version of Excel) the next time you open your workbook.

Then run the ChangeSheetNames macro.
 
Upvote 0
Select the column, press Ctrl-H and replace *- (asterisk dash) with nothing but I do not know how the remaining part (1.1, 2.1 etc) will be displayed in your date-system.
 
Upvote 0

Forum statistics

Threads
1,213,561
Messages
6,114,317
Members
448,564
Latest member
ED38

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