Oh, I forgot about that part, give a me a sec to update it so it will reuse the list
---------- Post added at 10:46 AM ---------- Previous post was at 10:41 AM ----------
Updated code:
Sub DummyMgmtNames()
'Replace Mgmt names with Dummy names
'Change this path to the correct path and file name, make sure to update the .xls to correct extension
Const strDummyNameFilePath As String = "C:\Test\Dummy Names.xls"
Dim rngSel As Range
Dim grp As Range
Dim lCalc As XlCalculation
Dim arrRealNames As Variant
Dim arrFakeNames As Variant
Dim NameIndex As Long
Dim lSuffix As Long
Dim i As Long
If TypeName(Selection) <> "Range" Then Exit Sub
Set rngSel = Selection
With Workbooks.Open(strDummyNameFilePath)
arrFakeNames = .Sheets(1).UsedRange.Value
.Close False
End With
With Application
lCalc = .Calculation
.Calculation = xlCalculationManual
.EnableEvents = False
.DisplayAlerts = False
.ScreenUpdating = False
End With
On Error GoTo CleanExit
With Sheets.Add
For Each grp In rngSel.Areas
For i = 1 To grp.Columns.Count
.Cells(.Rows.Count, "A").End(xlUp).Offset(1).Resize(grp.Rows.Count).Value = grp.Offset(, i - 1).Resize(, 1).Value
Next i
Next grp
.Range("A1").Value = "Names List"
.Range("A1").Font.Bold = True
.UsedRange.AdvancedFilter xlFilterCopy, , .Range("B1"), True
arrRealNames = .Range("B2", .Cells(.Rows.Count, "B").End(xlUp)).Value
.Delete
End With
lSuffix = 0
With rngSel
If IsArray(arrRealNames) Then
For i = LBound(arrRealNames, 1) To UBound(arrRealNames, 1)
If Not IsNumeric(arrRealNames(i, 1)) And Len(Trim(arrRealNames(i, 1))) > 0 Then
NameIndex = NameIndex + 1
If NameIndex > UBound(arrFakeNames, 1) Then
NameIndex = 1
lSuffix = lSuffix + 1
End If
If lSuffix > 0 Then
.Replace arrRealNames(i, 1), arrFakeNames(NameIndex, 1) & lSuffix, xlWhole
Else
.Replace arrRealNames(i, 1), arrFakeNames(NameIndex, 1), xlWhole
End If
End If
Next i
Else
If Not IsNumeric(arrRealNames) And Len(Trim(arrRealNames)) > 0 Then
.Replace arrRealNames, arrFakeNames(1, 1), xlWhole
End If
End If
End With
CleanExit:
With Application
.Calculation = lCalc
.EnableEvents = True
.DisplayAlerts = True
.ScreenUpdating = True
End With
If Err Then
MsgBox Err.Description, , "Error: " & Err.Number
Err.Clear
End If
Set rngSel = Nothing
Set grp = Nothing
Erase arrFakeNames
If IsArray(arrRealNames) Then Erase arrRealNames
End Sub
Bookmarks