lordabura
5/12/2015 - 11:39 AM

Macro

Macro

Public Function dvrut(rut)
    ' lo unico que no acepta son letras
    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

// Insertar → Módulo.
//en celda =dvrut(A1)