changing sheet's name

avishain

Board Regular
Joined
Dec 14, 2010
Messages
75
hello all,

i work with excel 2007.

i got 1 workbook which contains couple of worksheets.

i want that for each worksheet-the name of that spesific sheet will change according to the content in cell L2,however,with a small change:

the number in cell L2 has always 7 digits and i need only 4 from the second digit,for instance, if the number is 1234567 - i need to extract 2345 and use it for the name of the sheet.

in some cases the same number could appear more than once and then ill have the same name of the worksheet so i dont want to have an error msg...if there's a duplicate name i wish to add (1) or (2) and so on...


for instance,

ill have 1 sheet called 2133 and the second will be 2133(1) ...


thank u very much
 

Excel Facts

Workdays for a market open Mon, Wed, Friday?
Yes! Use "0101011" for the weekend argument in NETWORKDAYS.INTL or WORKDAY.INTL. The 7 digits start on Monday. 1 means it is a weekend.
try this

Code:
Sub Rename_Sheet()
Dim sh As Worksheet, flg As Boolean
Dim i As Long
Dim wFile As String
wFile = Mid(Range("L2"), 2, 4)
i = 1
For Each sh In Worksheets
    If sh.Name Like wFile Then
        flg = True
        i = i + 1
    End If
Next
If flg = True Then
    ActiveWorksheet.Name = wFile & "(" & i + 1 & ")"
End If
End Sub

note: untested
 
Last edited:
Upvote 0
try this

Code:
Sub Rename_Sheet()
Dim sh As Worksheet, flg As Boolean
Dim i As Long
Dim wFile As String
wFile = Mid(Range("L2"), 2, 4)
i = 1
For Each sh In Worksheets
    If sh.Name Like wFile Then
        flg = True
        i = i + 1
    End If
Next
If flg = True Then
    ActiveWorksheet.Name = wFile & "(" & i + 1 & ")"
End If
End Sub

note: untested


thanks but its not working....:(
 
Upvote 0

Forum statistics

Threads
1,224,602
Messages
6,179,848
Members
452,948
Latest member
UsmanAli786

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