Advertisement
YasserKhalil2019

T4483_Rename Worksheets By List Using Loops

Jan 2nd, 2020
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.58 KB | None | 0 0
  1. https://excel-egy.com/forum/t4483
  2. ---------------------------------
  3.  
  4. Sub Rename_Worksheets_By_List_Using_Loops()
  5. Dim ws As Worksheet, rng As Range, cnt As Long, i As Long
  6.  
  7. Set ws = ThisWorkbook.Worksheets(1)
  8. Set rng = ws.Range("A2:A" & ws.Cells(Rows.Count, 1).End(xlUp).Row)
  9. cnt = ThisWorkbook.Worksheets.Count
  10. If cnt <> rng.Cells.Count Then MsgBox "Worksheets Number Not The Same", vbExclamation: Exit Sub
  11.  
  12. For i = 1 To cnt
  13. ThisWorkbook.Worksheets(i).Name = CStr(ws.Cells(i + 1, 1).Value)
  14. Next i
  15.  
  16. MsgBox "Done...", 64
  17. End Sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement