Change tab name - delete 3 characters

TorrO

Board Regular
Joined
Feb 13, 2003
Messages
101
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
 

Some videos you may like

Excel Facts

Create a chart in one keystroke
Select the data and press Alt+F1 to insert a default chart. You can change the default chart to any chart type

slinky

Active Member
Joined
Dec 19, 2008
Messages
294
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:

TorrO

Board Regular
Joined
Feb 13, 2003
Messages
101
Office Version
  1. 2013
Platform
  1. Windows
So super easy, thanks slinky!!!
 

FormR

MrExcel MVP
Joined
Aug 18, 2011
Messages
6,464
Office Version
  1. 365
Platform
  1. Windows
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
 

slinky

Active Member
Joined
Dec 19, 2008
Messages
294

ADVERTISEMENT

No worries. There's probably a slightly more efficient way of doing it, but that works well enough for me!
 

slinky

Active Member
Joined
Dec 19, 2008
Messages
294
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..
 

FormR

MrExcel MVP
Joined
Aug 18, 2011
Messages
6,464
Office Version
  1. 365
Platform
  1. Windows

ADVERTISEMENT

if you don't mind..

Of course not, please feel free to use and abuse :)
 

hiker95

Well-known Member
Joined
Apr 8, 2009
Messages
17,649
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.
 

István Hirsch

Well-known Member
Joined
May 16, 2013
Messages
1,634
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.
 

slinky

Active Member
Joined
Dec 19, 2008
Messages
294
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.

That's not going to work to well for Worksheet names though?
 

Watch MrExcel Video

Forum statistics

Threads
1,122,539
Messages
5,596,754
Members
414,097
Latest member
FaeFen

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
Top