• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

1004 run time error

codedreamer

New Member
Hello,


I have a macro that changes the tab name of every worksheet in the workbook. It does work as long as all the worksheets in the workbook have data in them, but ocasionally, I will not be using all the worksheets. That is when I get a "run time error 1004"

Application-define or object define error.

How can I get the macro to still work even when I am not using all the worksheets?

Thank you,


codedreamer
 
Codedreamer


Can you paste the code your using?


I imagine it just needs to check that a certain cell has a value or not and if not skip that sheet
 
Yes, that is exactly what I need.

[pre]
Code:
For Each ws In ThisWorkbook.Worksheets
ws.Name = ws.Range("a1").Value
Next
[/pre]
Thank you for your help


codedreamer
 
[pre]
Code:
For Each ws In ThisWorkbook.Worksheets
If ws.Range("a1").Value <> "" then ws.Name = ws.Range("a1").Value
Next
[/pre]
 
Back
Top