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
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