Created
March 22, 2023 12:06
-
-
Save mikefrizzell/700f5955961ea5101d1528a3f42d6397 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Private Sub Worksheet_Change(ByVal Target As Range) | |
Dim cell As Range | |
Dim table As ListObject | |
Dim column As Integer | |
Dim emailDict As Object | |
Dim email As String | |
Set table = Me.ListObjects("Table1") | |
column = table.ListColumns("User").Index | |
' Create dictionary of email replacements | |
Set emailDict = CreateObject("Scripting.Dictionary") | |
emailDict.Add "first.last@domain.net", "Last, First" | |
emailDict.Add "john.doe@domain.net", "Doe, John" | |
' Add additional email replacements as needed | |
For Each cell In Target.Cells | |
If Not Intersect(cell, table.DataBodyRange) Is Nothing Then | |
If cell.Column = column Then | |
email = cell.Value | |
If emailDict.Exists(email) Then | |
cell.Value = emailDict(email) | |
End If | |
End If | |
End If | |
Next cell | |
End Sub |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This script will automatically find email addresses in Table1 column User and replace it with custom text pulled from a dictionary called emailDict. This is very specific to me because I pull a report with usernames as email addresses that I want to be lastname, firstname instead.