OldSoldier

New Member
Joined
Mar 29, 2011
Messages
13
Hi. I have this macro that names worksheets after each of the contents of a list.

The list drives output on a master worksheet related to the particular items from the list selected.

The macro selects each item and copies the contents of each filtered result into its own worksheet and renames that sheet after the contents of cell A2.

The problem is that the term in cell A2 is sufficiently long that the tabs end up having the same name and the macro errors out.

Here is the code:

Dim NewSheet As Worksheet
Dim Cell As Range
For Each Cell In Range("Combined")
Set NewSheet = Sheets.Add(After:=Sheets(Sheets.Count))
Sheets("Report").Range("ReportArea").Copy NewSheet.Range("A1")
NewSheet.Range("A2").Value = Cell.Value
NewSheet.Name = Left(NewSheet.Range("A2").Value, 31)
Sheets("Report").Range("StaffCounts").Copy
NewSheet.Range("U1").PasteSpecial Paste:=xlPasteFormulas, Operation:=xlNone, _
SkipBlanks:=False, Transpose:=False
Next Cell
End Sub

Can anyone help with this?

Thanks, OldSoldier
 

Excel Facts

What is =ROMAN(40) in Excel?
The Roman numeral for 40 is XL. Bill "MrExcel" Jelen's 40th book was called MrExcel XL.
I worked around this by making shorter names (they necessarily have to be pretty descriptive); however I find that the macro errors when I get down to the end of the list. It makes a new sheet and then breaks.

Thanks anyone!
 
Upvote 0
1. What exactly is the error message when the code 'breaks'?

2. When it does 'break' and you click 'Debug', what line of code is highlighted?

3. Tell us more about the named range "Combined". Which sheet? What range? What data (at least some of it if it is a large range)?
 
Upvote 0

Forum statistics

Threads
1,216,123
Messages
6,128,975
Members
449,480
Latest member
yesitisasport

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