Función personalizada (Excel) Para descomponer nombres y apellidos – Código libre.

0
11680

En alguna oportunidad hemos tenido la necesidad de separar los apellidos y nombres ya sea de nuestros trabajadores, clientes o proveedores y nos hemos encontrado con la tediosa tarea de hacerlo uno por uno ante esto PERU CONTABLE pone a su disposición un pequeño aplicativo para ser utilizado libremente en las tareas diarias si así lo deseamos.

asdasd

Para esto haremos uno de las funciones personalizadas que nos permite crear Excel dichas funciones son las contenidas en el código VBA adjuntado; ahora bien, el orden en que puede estar los datos son los siguientes:

1.- Apellidos y Nombres.

2.- Nombres y Apellidos.

Las funciones a usar son las siguientes:

  • Apellidos y nombres (1)

Apellido paterno= “APEL_PAT(N7;1)”

Apellido Materno= “APEL_MAT(N7;1)”

Primer nombre= “PRIMER_NOMBRE(N7;1)”

Segundo nombre= “SEGUNDO_NOMBRE(N7;1)”

  • Nombres y Apellidos (2)

Apellido paterno= “APEL_PAT(N11;2)”

Apellido Materno= “APEL_MAT(N11;2)”

Primer nombre= “PRIMER_NOMBRE(N11;2)”

Segundo nombre= “SEGUNDO_NOMBRE(N11;2)”

Para mayores detalles veamos el siguiente video:

Descargar archivo excel: libro1

Código en VBA (macros) utilizado.
Public I As Integer

Public N°_DIGITOS As Byte

Public ORDEN As Byte

Public criterio As Byte

Public DIG As String

Public w As String

Public XC As String

Public NOMBRE_APELLIDO As String

Public ID As Double

Public SEGUIR As Boolean

‘VISITA NUESTRA TIENDA VIRTUAL

‘SISTEMA CONTABLE EXCEL – ACCES V.3.0:::: http://www.perucontable.com/tienda/producto/sistema-contable-excel/

‘APLICATIVO PLE 5.0:::::::::::::::::::::: http://www.perucontable.com/tienda/producto/macro-aplicativo-libros-electronicos/

‘GESTOR DE PLANILLAS ELECTRONICAS:::::::: http://www.perucontable.com/tienda/producto/gestor-planillas-beneficios-sociales/

‘GESTOR DE INVENTARIOS::::::::::::::::::: http://www.perucontable.com/tienda/producto/control-almacen-excel/

Public Function APEL_PAT(DATO As String, TIPO As Byte) As String

Call TEMP(DATO)

N°_DIGITOS = Len(Trim(DATO))

DIG = Mid(Trim(DATO), 1, 1)

w = 1

XC = “”

NOMBRE_APELLIDO = “”

ORDEN = ORDEN – 1

Select Case ORDEN

Case 3

If TIPO = 1 Then criterio = 1 Else criterio = 2

Case 4

If TIPO = 1 Then criterio = 1 Else criterio = 3

End Select

ORDEN = 1

For II = 1 To N°_DIGITOS + 1

If DIG = ” ” Or II = N°_DIGITOS + 1 Then

NOMBRE_APELLIDO = XC

If ORDEN = 1 And criterio = ORDEN Then

APEL_PAT = NOMBRE_APELLIDO

ElseIf ORDEN = 2 And criterio = ORDEN Then

APEL_PAT = NOMBRE_APELLIDO

ElseIf ORDEN = 3 And criterio = ORDEN Then

APEL_PAT = NOMBRE_APELLIDO

ElseIf ORDEN = 4 And criterio = ORDEN Then

APEL_PAT = NOMBRE_APELLIDO

ElseIf ORDEN = 5 And criterio = ORDEN Then

APEL_PAT = NOMBRE_APELLIDO

End If

NOMBRE_APELLIDO = “”

‘FIN = 5

XC = “”

w = w + 1

DIG = Mid(Trim(DATO), w, 1)

ORDEN = ORDEN + 1

Else

XC = XC + DIG

w = w + 1

DIG = Mid(Trim(DATO), w, 1)

End If

Next II

End Function

Public Function APEL_MAT(DATO As String, TIPO As Byte) As String

Call TEMP(DATO)

N°_DIGITOS = Len(Trim(DATO))

DIG = Mid(Trim(DATO), 1, 1)

w = 1

XC = “”

NOMBRE_APELLIDO = “”

ORDEN = ORDEN – 1

Select Case ORDEN

Case 3

If TIPO = 1 Then criterio = 2 Else criterio = 3

Case 4

If TIPO = 1 Then criterio = 2 Else criterio = 4

End Select

ORDEN = 1

For II = 1 To N°_DIGITOS + 1

If DIG = ” ” Or II = N°_DIGITOS + 1 Then

NOMBRE_APELLIDO = XC

If ORDEN = 1 And criterio = ORDEN Then

APEL_MAT = NOMBRE_APELLIDO

ElseIf ORDEN = 2 And criterio = ORDEN Then

APEL_MAT = NOMBRE_APELLIDO

ElseIf ORDEN = 3 And criterio = ORDEN Then

APEL_MAT = NOMBRE_APELLIDO

ElseIf ORDEN = 4 And criterio = ORDEN Then

APEL_MAT = NOMBRE_APELLIDO

ElseIf ORDEN = 5 And criterio = ORDEN Then

APEL_MAT = NOMBRE_APELLIDO

End If

NOMBRE_APELLIDO = “”

‘FIN = 5

XC = “”

w = w + 1

DIG = Mid(Trim(DATO), w, 1)

ORDEN = ORDEN + 1

Else

XC = XC + DIG

w = w + 1

DIG = Mid(Trim(DATO), w, 1)

End If

Next II

End Function

Public Function PRIMER_NOMBRE(DATO As String, TIPO As Byte) As String

Call TEMP(DATO)

N°_DIGITOS = Len(Trim(DATO))

DIG = Mid(Trim(DATO), 1, 1)

w = 1

XC = “”

NOMBRE_APELLIDO = “”

ORDEN = ORDEN – 1

Select Case ORDEN

Case 3

If TIPO = 1 Then criterio = 3 Else criterio = 1

Case 4

If TIPO = 1 Then criterio = 3 Else criterio = 1

End Select

ORDEN = 1

For II = 1 To N°_DIGITOS + 1

If DIG = ” ” Or II = N°_DIGITOS + 1 Then

NOMBRE_APELLIDO = XC

If ORDEN = 1 And criterio = ORDEN Then

PRIMER_NOMBRE = NOMBRE_APELLIDO

ElseIf ORDEN = 2 And criterio = ORDEN Then

PRIMER_NOMBRE = NOMBRE_APELLIDO

ElseIf ORDEN = 3 And criterio = ORDEN Then

PRIMER_NOMBRE = NOMBRE_APELLIDO

ElseIf ORDEN = 4 And criterio = ORDEN Then

PRIMER_NOMBRE = NOMBRE_APELLIDO

ElseIf ORDEN = 5 And criterio = ORDEN Then

PRIMER_NOMBRE = NOMBRE_APELLIDO

End If

NOMBRE_APELLIDO = “”

‘FIN = 5

XC = “”

w = w + 1

DIG = Mid(Trim(DATO), w, 1)

ORDEN = ORDEN + 1

Else

XC = XC + DIG

w = w + 1

DIG = Mid(Trim(DATO), w, 1)

End If

Next II

End Function

Public Function SEGUNDO_NOMBRE(DATO As String, TIPO As Byte) As String

Call TEMP(DATO)

N°_DIGITOS = Len(Trim(DATO))

DIG = Mid(Trim(DATO), 1, 1)

w = 1

XC = “”

NOMBRE_APELLIDO = “”

ORDEN = ORDEN – 1

Select Case ORDEN

Case 3

If TIPO = 1 Then criterio = 5 Else criterio = 5

Case 4

If TIPO = 1 Then criterio = 4 Else criterio = 2

End Select

ORDEN = 1

For II = 1 To N°_DIGITOS + 1

If DIG = ” ” Or II = N°_DIGITOS + 1 Then

NOMBRE_APELLIDO = XC

If ORDEN = 1 And criterio = ORDEN Then

SEGUNDO_NOMBRE = NOMBRE_APELLIDO

ElseIf ORDEN = 2 And criterio = ORDEN Then

SEGUNDO_NOMBRE = NOMBRE_APELLIDO

ElseIf ORDEN = 3 And criterio = ORDEN Then

SEGUNDO_NOMBRE = NOMBRE_APELLIDO

ElseIf ORDEN = 4 And criterio = ORDEN Then

SEGUNDO_NOMBRE = NOMBRE_APELLIDO

ElseIf ORDEN = 5 And criterio = ORDEN Then

SEGUNDO_NOMBRE = NOMBRE_APELLIDO

End If

NOMBRE_APELLIDO = “”

‘FIN = 5

XC = “”

w = w + 1

DIG = Mid(Trim(DATO), w, 1)

ORDEN = ORDEN + 1

Else

XC = XC + DIG

w = w + 1

DIG = Mid(Trim(DATO), w, 1)

End If

Next II

End Function

Public Function TEMP(DATO As String)

N°_DIGITOS = Len(Trim(DATO))

DIG = Mid(Trim(DATO), 1, 1)

w = 1

XC = “”

NOMBRE_APELLIDO = “”

ORDEN = 1

For II = 1 To N°_DIGITOS + 1

If DIG = ” ” Or II = N°_DIGITOS + 1 Then

NOMBRE_APELLIDO = XC

NOMBRE_APELLIDO = “”

‘FIN = 5

XC = “”

w = w + 1

DIG = Mid(Trim(DATO), w, 1)

ORDEN = ORDEN + 1

Else

XC = XC + DIG

w = w + 1

DIG = Mid(Trim(DATO), w, 1)

End If

Next II

End Function

Esperamos que sea de utilidad hasta el siguiente post un saludo contable.

Comentarios

PROGRAMA DE ESPECIALIZACION GESTIÓN TRIBUTARIA

Inicia: Sabado 23 de Marzo

Horario: 6:30 p.m. - 10:30 p.m.

Frecuencia: 1 una vez

Modalidad: EN VIVO



0 0 votes
Article Rating
Suscribe
Notify of
guest

0 Comentarios
Inline Feedbacks
View all comments