Skip Worksheets With Looping Coding

  • Thread starter Joe_Hunt via OfficeKB.com
  • Start date
J

Joe_Hunt via OfficeKB.com

Hey all,
I have some coding that loops through a workbook and puts the tab name in
cell B5 of multiple worksheets (around 265 or so this month). This has worked
very well until this month in that I have a protected worksheet, not
protected by me so I don't have the password, that causes Excel to error out
when it comes to it. How can I get it to skip that worksheet? Here's the
coding I've been using.

Sub TabNameInCellB5()

Dim iSheet As Long
Application.ScreenUpdating = False
For iSheet = 1 To ActiveWorkbook.Worksheets.Count
Worksheets(iSheet).Cells(5, 2) = "'" & Worksheets(iSheet).Name
Next iSheet
Application.ScreenUpdating = True

End Sub

Any help would be very appreciated.
 
J

Jim Thomlinson

Sub TabNameInCellB5()

Dim iSheet As Long
Application.ScreenUpdating = False
On error resume next 'ignore errors
For iSheet = 1 To ActiveWorkbook.Worksheets.Count
Worksheets(iSheet).Cells(5, 2) = "'" & Worksheets(iSheet).Name
Next iSheet
on error goto 0 'resume checking for errors
Application.ScreenUpdating = True

End Sub
 
J

Joe_Hunt via OfficeKB.com

Thanks!

Jim said:
Sub TabNameInCellB5()

Dim iSheet As Long
Application.ScreenUpdating = False
On error resume next 'ignore errors
For iSheet = 1 To ActiveWorkbook.Worksheets.Count
Worksheets(iSheet).Cells(5, 2) = "'" & Worksheets(iSheet).Name
Next iSheet
on error goto 0 'resume checking for errors
Application.ScreenUpdating = True

End Sub
Hey all,
I have some coding that loops through a workbook and puts the tab name in
[quoted text clipped - 16 lines]
Any help would be very appreciated.
 

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