Data Loading Salesforce
July 17, 2022
Use this quick Excel hack to speed up data prep.
My real-world use case: client has 2 multi-select picklist fields that are being combined, then the values are being replaced with new values.
So, we’ll add in a snippet of VBA (fyi that stands for Visual Basic for Applications, which is Excel’s programming language, but if you’re like me you’re thinking NO ONE CARES GET ON WITH IT.)
Paste this somewhere convenient for reference in the sheet you want to update.
Right click on the tab of the Excel sheet you want to complete the find and replace on. Click “View Code.”
An empty VBA code box appears.
Option Explicit
Sub FindnReplaceMultipleValues()
Dim Rng As Range
Dim OldText As Range
Dim ReplaceData As Range
On Error Resume Next
Set OldText = Application.InputBox("Select Old Text Range:", "Find And Replace Multiple Values", Application.Selection.Address, Type:=8)
Err.Clear
If Not OldText Is Nothing Then
Set ReplaceData = Application.InputBox("Replace What And With:", "Find And Replace Multiple Values", Type:=8)
Err.Clear
If Not ReplaceData Is Nothing Then
Application.ScreenUpdating = False
For Each Rng In ReplaceData.Columns(1).Cells
OldText.Replace what:=Rng.Value, replacement:=Rng.Offset(0, 1).Value
Next
Application.ScreenUpdating = True
End If
End If
End Sub
The VBA code box will now look like this.
Next, click F5. If you’re on a Mac, hold down the fn (function) button in the lower left corner and click the F5 button across the top of the keyboard.
You will see a dialog box that prompts you to “Select Old Text Range:”.
In the above example, we want to replace the value of cells E2 to E13.
Click the “ok” button in the dialog box, and a second dialog box appears that says “Replace What And With”.
This is prompting you to select the range of cells containing the old values and the corresponding new value that will replace the old value.
In the above example, the range I entered says H4 to I7.
Click the “ok” button.
In the above screenshot, you can see the “To be updated” column now shows updated data.
This works when there are multiple values in a cell to be replaced as well.
Follow the same instructions to complete the find and replace.
Now, to address all the haters.
Yes, I’m going to add it to this computer with these add-in instructions.
But I digress…
In cell F2, I’d have written the following formula:
=XLOOKUP($E2,$H$4:$H$7,$I$4:$I$7,$E2)
Let’s break apart this formula to understand what it’s doing.
I’ll send you a new Salesforce tutorial every week, because that’s just the kind of gal I am.