Public Function CUITValido(CUIT As String) As Boolean
' Verifica que strCUIT sea un número de CUIT o CUIL válido
Dim i As Integer
Const FACTORES = "54327654321"
Dim lngSuma As Long
CUITValido = False
On Error GoTo Errores
If Len(CUIT) <> 11 Then
Exit Function 'debe tener 11 dígitos
Else
If Left(CUIT, 1) <> "3" And Left(CUIT, 1) <> "2" Then
Exit Function
Else
If IsNumeric(CUIT) Then
For i = 1 To 11
lngSuma = lngSuma + (Val(Mid(CUIT, i, 1)) * Val(Mid(FACTORES, i, 1)))
Next i
CUITValido = (lngSuma Mod 11 = 0)
End If
End If
End If
Errores:
End Function
|