ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Rename worksheets of workbook - Error code (https://www.excelbanter.com/excel-programming/393855-rename-worksheets-workbook-error-code.html)

[email protected]

Rename worksheets of workbook - Error code
 
Can anybody modify macro below to make it continue running even if it
can't rename a worksheet (sheetname can't take cell content) i.e
rename all other sheets.

Sub Renamesheetloop()
For Each ws In Worksheets
ws.Name = ws.Range("A1").Value
Next ws
End Sub

Thxs


Dave Peterson

Rename worksheets of workbook - Error code
 
Sub Renamesheetloop()
For Each ws In Worksheets
on error resume next
ws.Name = ws.Range("A1").Value
on error goto 0
Next ws
End Sub

or

Sub Renamesheetloop()
For Each ws In Worksheets
on error resume next
ws.Name = ws.Range("A1").Value
if err.number = 0 then
'ok
else
msgbox "rename of sheet: " & ws.name & " failed"
err.clear
end if
on error goto 0
Next ws
End Sub

wrote:

Can anybody modify macro below to make it continue running even if it
can't rename a worksheet (sheetname can't take cell content) i.e
rename all other sheets.

Sub Renamesheetloop()
For Each ws In Worksheets
ws.Name = ws.Range("A1").Value
Next ws
End Sub

Thxs


--

Dave Peterson


All times are GMT +1. The time now is 10:08 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com