Please can you help me debug this code?

lucie19

New Member
Joined
Apr 28, 2014
Messages
6
Hi All

I'm trying to get a button to apply the contents of A1 to the tab name on every sheet, (if that makes sense?)

I was using this code successfully on some other similar spreadsheets but now it simply won't work. I am getting this error "Run-time error '1004': Method 'Name' of object' _Worksheet' failed

The code I am using is below.

Thanks as always for your help.

Sub myTabNames()
Dim ws As Worksheet
For Each ws in ActiveWorkbook.Worksheets
ws.Name = ws.Range("A1").Value
Next
End Sub
 

Excel Facts

How to find 2nd largest value in a column?
MAX finds the largest value. =LARGE(A:A,2) will find the second largest. =SMALL(A:A,3) will find the third smallest
What do you mean "the contents of A1 to the tab name on every sheet".
The code, as written, tries to make the tab name of every sheet the same as the value of range("A1") of that sheet.
The error sounds like either there is an illegal sheet name in A1 of some sheet (like a blank cell), or that there may be a duplicate value in A1.
 
Upvote 0

Forum statistics

Threads
1,214,839
Messages
6,121,891
Members
449,058
Latest member
Guy Boot

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top