Hi I have the following code, that puts all names from the name manager into a combo box and removes duplicates and other certain phrases, in this case "CutOffTesting!_FilterD". I want to remove/ignore a second phrase, but can't seem to get it to work.
Private Sub UserForm_Initialize()
' Clear the ComboBox to ensure no duplicate values
ComboBox1.Clear
' Create a collection to store unique base names
Dim BaseNames As Collection
Set BaseNames = New Collection
' Loop through all Name Manager entries and extract base names
Dim nm As Name
For Each nm In ThisWorkbook.Names
' Extract the base name (e.g., "WMP001")
Dim BaseName1 As String
BaseName1 = Left(nm.Name, Len(nm.Name) - 7) ' Remove "Routine" or "Sensory"
' Check if the base name is not already added to the collection
If InStr(1, nm.Name, "CutOffTesting!_FilterD", vbTextCompare) = 0 Then
On Error Resume Next
BaseNames.Add BaseName1, CStr(BaseName1)
On Error GoTo 0
End If
Next nm
' Populate the ComboBox with unique base names
Dim BaseName2 As Variant
For Each BaseName2 In BaseNames
ComboBox1.AddItem BaseName2
Next BaseName2
' Initialize other fields with default values or empty fields
TextBox2.Value = ""
TextBox3.Value = ""
End Sub
Private Sub UserForm_Initialize()
' Clear the ComboBox to ensure no duplicate values
ComboBox1.Clear
' Create a collection to store unique base names
Dim BaseNames As Collection
Set BaseNames = New Collection
' Loop through all Name Manager entries and extract base names
Dim nm As Name
For Each nm In ThisWorkbook.Names
' Extract the base name (e.g., "WMP001")
Dim BaseName1 As String
BaseName1 = Left(nm.Name, Len(nm.Name) - 7) ' Remove "Routine" or "Sensory"
' Check if the base name is not already added to the collection
If InStr(1, nm.Name, "CutOffTesting!_FilterD", vbTextCompare) = 0 Then
On Error Resume Next
BaseNames.Add BaseName1, CStr(BaseName1)
On Error GoTo 0
End If
Next nm
' Populate the ComboBox with unique base names
Dim BaseName2 As Variant
For Each BaseName2 In BaseNames
ComboBox1.AddItem BaseName2
Next BaseName2
' Initialize other fields with default values or empty fields
TextBox2.Value = ""
TextBox3.Value = ""
End Sub