1

I have to rename my selected sheets (tabs of sheets) continuously in order to keep them updated with new additions i.e. sorting them based on new names, numbers or other criteria.

I have made a table of all the names in one particular sheet and after processing that table (changing names, numbers etc) I want to use it to rename the currently selected sheets only.

e.g. I select ANY 5 sheets and I want a code that will rename ONLY those 5 sheets based on FIRST FIVE values from the table in particular SHEET.

I did little bit of scratch work as below but it's not leading me anywhere.

Sub Sheets_Naming_current()

Dim ws As Worksheet, wb As Workbook
Dim nmRange As Range
Dim count As Integer

Set wb = ActiveWorkbook
Set nmRange = wb.Sheets("Totals").Range("D2:D25")
count = 0
On Error Resume Next
For Each ws In ActiveWindow.SelectedSheets
 count = count + 1     
      ws.Name = nmRange.Offset(i, 0).Value
Next ws


End Sub

Thanks in advance!

2 Answers 2

0

You need to made some changes inside the loop.

First- your i variable returns zero all the time, you rather need to use count variable when offsetting.

Second- instead of offset I would suggest to use Cells() reference like presented below.

Proposed loop could be as follows:

'...your code here
For Each ws In ActiveWindow.SelectedSheets

      count = count + 1
      ws.Name = nmRange.Cells(count).Value

Next ws
'...your code here
2
  • KazJaw that was excellent solution. Count should've started at 0 so that I don't miss a name in list. Excellent solution and it WORKED ! May 26, 2013 at 9:30
  • Happy I was able to help. So, please use StackOverflow feature to mark answer as answered. You could do it also in other question of yours. That's what we like when helping people :) May 26, 2013 at 9:33
0

Try below code :

Sub Sheets_Naming_current()

    Dim ws As Worksheet, wb As Workbook
    Dim count As Integer

    Set wb = ActiveWorkbook
    count = 2
    On Error Resume Next

    For Each ws In ActiveWindow.SelectedSheets
        With Sheets("Totals")
            If ws.Name <> "Totals" And .Cells(count, 4) <> "" Then
                ws.Name = .Cells(count, 4)
                count = count + 1
            End If
        End With
    Next ws

End Sub
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.