Skip to content

Instantly share code, notes, and snippets.

@trevorcgibson
Created July 25, 2013 23:25
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save trevorcgibson/6084727 to your computer and use it in GitHub Desktop.
Save trevorcgibson/6084727 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