Re: Separate data from each owner into separate sheet?
I follow up the instruction u mention, And I got an error message indicating
Run-time error '1004':
You typed an invalid name for a sheet or chart. Make sure that:
* The name that you type does not exceed 31 characters.
* The name does not contain any of the following characters: : \ / ?
[ or ]
* You did not leave the name blank.
After clicking debug it highlight yellow color this line
Sheets(Sheets.Count).Name = kee
&&&
The whole code in the Module 1 is :
Option Explicit
Sub SplitByOwner()
Dim x, y(), z, kee, i As Long, ii As Long, iii As Long, iv As Long, oDic As Object
Set oDic = CreateObject("scripting.dictionary")
oDic.CompareMode = 1
x = Sheets("sheet1").Cells(1).CurrentRegion
For i = 2 To UBound(x, 1)
If Len(x(i, 10)) Then
kee = oDic.Item(x(i, 10))
If IsEmpty(kee) Then
For ii = 2 To UBound(x, 1)
If x(ii, 10) = x(i, 10) Then
iv = iv + 1: ReDim Preserve y(1 To 14, 1 To iv)
For iii = 1 To 3
y(iii, iv) = x(ii, iii)
Next
y(4, iv) = x(ii, 5): y(5, iv) = x(ii, 10): y(14, iv) = x(ii, 31)
For iii = 6 To 13
y(iii, iv) = x(ii, iii + 16)
Next
End If
Next
oDic.Item(x(i, 10)) = y
End If
End If
Erase y: iv = 0
Next
Application.ScreenUpdating = 0
For Each kee In oDic.keys
If Not SheetExists(CStr(kee)) Then
Sheets("Template").Copy , Sheets(Sheets.Count)
Sheets(Sheets.Count).Name = kee
End If
z = TransposeArray(oDic.Item(kee))
With Sheets(kee)
.Rows(2).Resize(.UsedRange.Rows.Count).Delete
.[a2].Resize(UBound(z, 1), 14) = z
With .UsedRange.Offset(1)
.Columns(2).WrapText = True
.VerticalAlignment = -4108
End With
.Columns.AutoFit
End With
Next
Sheets("sheet1").Activate
Application.ScreenUpdating = 1
MsgBox "Data successfully copied to Owner Sheets.", 64, "Completed"
End Sub
Function SheetExists(sName As String) As Boolean
SheetExists = Evaluate("ISREF('" & sName & "'!A1)")
End Function
Function TransposeArray(Arr As Variant) As Variant
Dim temp, a As Long, b As Long, i As Long, ii As Long
i = UBound(Arr, 2): ii = UBound(Arr, 1)
ReDim temp(1 To i, 1 To ii)
For a = 1 To i
For b = 1 To ii
temp(a, b) = Arr(b, a)
Next
Next
TransposeArray = temp
End Function
Display More
I think that happens due to WO Owner Name is a lot charachters than Project Manager Name right ?