Skip to content

Instantly share code, notes, and snippets.

@stgoos
Forked from trevorcgibson/Excel VBA - SFDC 15 to 18
Created September 26, 2022 15:36
Show Gist options
  • Save stgoos/7181f7c4eae6b8c12ea34cf690b243dc to your computer and use it in GitHub Desktop.
Save stgoos/7181f7c4eae6b8c12ea34cf690b243dc to your computer and use it in GitHub Desktop.
VBA code for Microsoft Excel to convert 15-digit Salesforce.com record ids to their 18-digit checksum version. Use by adding into a new module in the Excel VBA code editor. NOTE: I did not write this - but can't quite remember who/where I got it from. If it's yours, please let me know and I'll update to provide attribution.
Function FixID(InID As String) As String
If Len(InID) = 18 Then
FixID = InID
Exit Function
End If
Dim InChars As String, InI As Integer, InUpper As String
Dim InCnt As Integer
InChars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ012345"
InUpper = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
InCnt = 0
For InI = 15 To 1 Step -1
InCnt = 2 * InCnt + Sgn(InStr(1, InUpper, Mid(InID, InI, 1), vbBinaryCompare))
If InI Mod 5 = 1 Then
FixID = Mid(InChars, InCnt + 1, 1) + FixID
InCnt = 0
End If
Next InI
FixID = InID + FixID
End Function
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment