Naming worksheet based on value in cell...ERROR message

vik2slick

New Member
Joined
Dec 28, 2017
Messages
23
Hi,

I am trying to rename my worksheets (540 of them) based on the value in cell A200 (which is a formula pulling together 3 cells, so =A1&" "&B1&" "&A3 ). I've checked all the sheets to make sure there is a value in cell A200. However, when I run the below macro, I get a Run-time error.

VBA used
Sub test()
Dim ws As Worksheet
For Each ws In ActiveWorkbook.Worksheets
ws.Activate
ActiveSheet.Name = Range("A200").Value
Next ws
End Sub


Error received when VBA used
Run-time error '1004':
Application-defined or object-defined error


Can anyone help/advise?
 

Excel Facts

Is there a shortcut key for strikethrough?
Ctrl+S is used for Save. Ctrl+5 is used for Strikethrough. Why Ctrl+5? When you use hashmarks to count |||| is 4, strike through to mean 5.
Does this work any better?
Code:
Sub test()
Dim ws As Worksheet

    For Each ws In ActiveWorkbook.Worksheets
        ws.Name = ws.Range("A200").Value
    Next ws

End Sub
 
Upvote 0
Worked for the first 22 sheets but the error popped up again. I checked the 23rd sheet to see if there was any mistake but none that i can see. There is a value there.
 
Upvote 0
Try this:
Code:
Sub My_Sheet_Names()
Application.ScreenUpdating = False
'Modified  9/26/2018  7:10:38 PM  EDT
Dim i As Long
On Error GoTo M
    For i = 1 To Sheets.Count
        Sheets(i).Name = Sheets(i).Range("A200").Value
    Next
Application.ScreenUpdating = True
Exit Sub
M:
MsgBox "That sheet name may have already been used or is a improper sheet name"
Application.ScreenUpdating = True
End Sub
 
Upvote 0
Came back with MsgBox "That sheet name may have already been used or is a improper sheet name". The characters in that cell are a few more than the limit for the tab name. Thank you!!
 
Upvote 0
So you need to fix that. The limit is unknow to me.

And there are some characters you cannot use like /
 
Upvote 0

Forum statistics

Threads
1,214,976
Messages
6,122,539
Members
449,088
Latest member
RandomExceller01

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