Replace Sub GenerateNames() in "Detail" sheet module with
Sub GenerateNames()
Dim a, i As Long, e, s, t, dic As Object, temp As String
With Application
.ScreenUpdating = False
.EnableEvents = False
.DisplayAlerts = False
.Calculation = xlCalculationManual
On Error Resume Next
Sheets("hiddennames").Visible = -1
Sheets("hiddennames").Delete
On Error GoTo 0
Set dic = CreateObject("Scripting.Dictionary")
dic.CompareMode = 1
a = Range("a3").CurrentRegion.Value
For i = 3 To UBound(a, 1)
a(i, 1) = CStr(a(i, 1))
If Not dic.exists(a(i, 1)) Then
Set dic(a(i, 1)) = CreateObject("Scripting.Dictionary")
dic(a(i, 1)).CompareMode = 1
End If
a(i, 3) = StrConv(a(i, 3), 3)
If Not dic(a(i, 1)).exists(a(i, 3)) Then
Set dic(a(i, 1))(a(i, 3)) = CreateObject("System.Collections.ArrayList")
End If
a(i, 4) = StrConv(a(i, 4), 3)
If Not dic(a(i, 1))(a(i, 3)).Contains(a(i, 4)) Then
dic(a(i, 1))(a(i, 3)).Add a(i, 4)
End If
Next
With Sheets.Add
.Name = "hiddennames"
.Visible = 2
t = t + 1
With .Cells(1, t).Resize(dic.Count)
.Value = Application.Transpose(dic.keys)
.Name = "MyList"
End With
For Each e In dic
On Error Resume Next
ThisWorkbook.Names("z_" & e).Delete
Err.Clear
t = t + 1
With .Cells(1, t).Resize(dic(e).Count)
.Value = Application.Transpose(dic(e).keys)
.Name = "z_" & e
End With
For Each s In dic(e).keys
t = t + 1
On Error Resume Next
temp = GetCleanName(s)
ThisWorkbook.Names("z_" & e & "_" & temp).Delete
Err.Clear
With .Cells(1, t).Resize(dic(e)(s).Count)
.Value = Application.Transpose(dic(e)(s).ToArray)
.Name = "z_" & e & "_" & temp
End With
Next
Next
End With
With Range("a2", Range("a" & Rows.Count).End(xlUp)).Offset(, 4)
With .Validation
.Delete
.Add xlValidateList, Formula1:="=mylist"
End With
End With
.ScreenUpdating = True
.EnableEvents = True
.DisplayAlerts = True
.Calculation = xlCalculationAutomatic
End With
End Sub
Bookmarks