Skip to content

Instantly share code, notes, and snippets.

@snake575
Created July 9, 2019 17:19
Show Gist options
  • Save snake575/2a46fd48eb26658e5d7cf7ade3e18cf4 to your computer and use it in GitHub Desktop.
Save snake575/2a46fd48eb26658e5d7cf7ade3e18cf4 to your computer and use it in GitHub Desktop.
Public Function RUTDV(rut)
rut = Replace("0000" & rut, ".", "", 1)
If InStr(1, rut, "-") > 0 Then rut = Left(rut, InStr(1, rut, "-") - 1)
rut = Right(rut, 8)
suma = 0
For i = 1 To 8
suma = suma + Val(Mid(rut, i, 1)) * Val(Mid("32765432", i, 1))
Next i
dv = 11 - (suma Mod 11)
If dv = 10 Then dv = "k"
If dv = 11 Then dv = 0
dvrut = dv
End Function
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment