Rename worksheets of workbook - Error code

T

transferxxx

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
 
D

Dave Peterson

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top