简体   繁体   中英

Worksheet Tab name change based on cell value

I want to change the worksheet tab names based on the cell value its changing only in sheet 1 other sheets not changing

nothing

Public Sub ChangeSheetNames()
    Dim ws As Worksheet

    'lastRow = ws.Cells(Rows.Count, "A").End(xlUp).Row
    'For i = 2 To lastRow
    On Error Resume Next
    For Each ws In Worksheets
    'ws.Tab = ws.Cells(i, 2)

       If ws.Range("A2").Value <> "" Then
          ws.Name = ws.Range("A2").Value
       End If

    Next ws
End Sub

changing only for sheet 1 I need to change min 50 sheets

Try this macro:

Public Sub ChangeSheetNames()
    Dim lLastRow As Long
    With Worksheets(1)
        lLastRow = .Cells(Rows.Count, 1).End(xlUp).Row
        For i = 1 To Worksheets.Count
            If .Cells(i, 1).Value <> "" Then Worksheets(i).Name = .Cells(i, 1).Value
        Next
    End With
End Sub

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM