1 Copia estas rutinas en un módulo estándar en tu libro y guárdalo como xlsm.
2 Crea las hojas Telefonos, Clientes, Direcciones, emails y Tarjetas. (vuelve a guardar el libro)
3 Ejecuta las rutinas (de una en una). Cada rutina carga los datos en una hoja. Cuando ejecutes cada rutina tienes que borrar duplicados (menú datos, quitar duplicados (deja todas las columnas marcadas) y ordenar por código de
cliente.
La última rutina, que es la fundamental para ti, está inacabada porque no entiendo bien lo que haces y el contenido de algunas columnas (tendrás que explicarte mejor). Solo he añadido una columna para distinguir los registros de
retención de los de recuperación.
Si observas la hoja Direcciones, verás que, aunque se han eliminado los registros duplicados (y hay duplicados porque los datos de partida están mal y están mal porque se tratan mal) todavía hay muchos registros
que son iguales (aunque no idénticos), esto es debido a que los datos de partida están mal y están mal porque se tratan mal. Lo mismo o parecido en las otras hojas.
Sub Telefonos()
Dim H1 As Worksheet
Dim H2 As Worksheet
Dim f1 As Long
Dim f2 As Long
Dim c1 As Integer
Dim T1 As Single
Dim CodigoCliente As String
Dim Nombre As String
Application.ScreenUpdating = False
T1 = Timer()
Set H1 = Worksheets("Sheet1") ' hoja entrada
Set H2 = Worksheets("Telefonos") 'CREAR LA HOJA ANTES SI NO EXISTE
f2 = 2
With H1
For f1 = 2 To .Cells(100000, 1).End(xlUp).Row
CodigoCliente = Trim$(CStr(.Cells(f1, 5)))
Nombre = Trim$(.Cells(f1, 7))
For c1 = 48 To 69
If Len(.Cells(f1, c1)) Then
H2.Cells(f2, 1) = CodigoCliente
H2.Cells(f2, 2) = Nombre
H2.Cells(f2, 3) = CStr(.Cells(f1, c1))
f2 = f2 + 1
End If
Next
Next
End With
' borrar filas duplicadas
' ordenar
MsgBox "he finalizado el trabajo" & vbCrLf & "Tiempo empleado: " & Timer() - T1
End Sub
Sub Clientes()
Dim H1 As Worksheet
Dim H2 As Worksheet
Dim f1 As Long
Dim f2 As Long
Dim c1 As Integer
Dim T1 As Single
Application.ScreenUpdating = False
T1 = Timer()
Set H1 = Worksheets("Sheet1") ' hoja entrada
Set H2 = Worksheets("Clientes") 'CREAR LA HOJA ANTES SI NO EXISTE
f2 = 2
With H1
For f1 = 2 To .Cells(100000, 1).End(xlUp).Row
H2.Cells(f2, 1) = Trim$(CStr(.Cells(f1, 5))) ' codigo cliente
H2.Cells(f2, 2) = Trim$(.Cells(f1, 7)) ' nombre cliente
H2.Cells(f2, 3) = .Cells(f1, 8) ' fecha nacimiento
H2.Cells(f2, 4) = .Cells(f1, 9) ' nit
H2.Cells(f2, 5) = Trim$(.Cells(f1, 10)) ' luga emision
H2.Cells(f2, 6) = .Cells(f1, 11) ' dpi
f2 = f2 + 1
Next
End With
' borrar filas duplicadas
' ordenar
MsgBox "he finalizado el trabajo" & vbCrLf & "Tiempo empleado: " & Timer() - T1
End Sub
Sub Direcciones()
Dim H1 As Worksheet
Dim H2 As Worksheet
Dim f1 As Long
Dim f2 As Long
Dim c1 As Integer
Dim T1 As Single
Dim CodigoCliente As String
Dim Nombre As String
Application.ScreenUpdating = False
T1 = Timer()
Set H1 = Worksheets("Sheet1") ' hoja entrada
Set H2 = Worksheets("Direcciones") 'CREAR LA HOJA ANTES SI NO EXISTE
f2 = 2
With H1
For f1 = 2 To .Cells(100000, 1).End(xlUp).Row
CodigoCliente = Trim$(CStr(.Cells(f1, 5)))
Nombre = Trim$(.Cells(f1, 7))
For c1 = 71 To 155 Step 6
If Len(.Cells(f1, c1)) Then
H2.Cells(f2, 1) = CodigoCliente
H2.Cells(f2, 2) = Nombre
H2.Cells(f2, 3) = CStr(.Cells(f1, c1)) ' nomenclatura
H2.Cells(f2, 4) = CStr(.Cells(f1, c1 + 1)) ' zona
H2.Cells(f2, 5) = CStr(.Cells(f1, c1 + 2)) ' colonia
H2.Cells(f2, 6) = CStr(.Cells(f1, c1 + 3)) ' departamento
H2.Cells(f2, 7) = CStr(.Cells(f1, c1 + 4)) ' municipio
H2.Cells(f2, 8) = CStr(.Cells(f1, c1 + 5)) ' tipo direccion
f2 = f2 + 1
End If
Next
Next
End With
' borrar filas duplicadas
' ordenar
MsgBox "he finalizado el trabajo" & vbCrLf & "Tiempo empleado: " & Timer() - T1
End Sub
Sub emails()
Dim H1 As Worksheet
Dim H2 As Worksheet
Dim f1 As Long
Dim f2 As Long
Dim c1 As Integer
Dim T1 As Single
Dim CodigoCliente As String
Dim Nombre As String
Application.ScreenUpdating = False
T1 = Timer()
Set H1 = Worksheets("Sheet1") ' hoja entrada
Set H2 = Worksheets("emails") 'CREAR LA HOJA ANTES SI NO EXISTE
f2 = 2
With H1
For f1 = 2 To .Cells(100000, 1).End(xlUp).Row
CodigoCliente = Trim$(CStr(.Cells(f1, 5)))
Nombre = Trim$(.Cells(f1, 7))
For c1 = 156 To 157
If Len(.Cells(f1, c1)) Then
H2.Cells(f2, 1) = CodigoCliente
H2.Cells(f2, 2) = Nombre
H2.Cells(f2, 3) = CStr(.Cells(f1, c1))
f2 = f2 + 1
End If
Next
Next
End With
' borrar filas duplicadas
' ordenar
MsgBox "he finalizado el trabajo" & vbCrLf & "Tiempo empleado: " & Timer() - T1
End Sub
Sub RetencionRecuperacion()
Dim H1 As Worksheet
Dim H2 As Worksheet
Dim H3 As Worksheet
Dim f1 As Long
Dim f2 As Long
Dim f3 As Long
Dim T1 As Single
Application.ScreenUpdating = False
T1 = Timer()
Set H1 = Worksheets("Sheet1") ' hoja entrada
Set H2 = Worksheets("Tarjetas") 'CREAR LA HOJA ANTES SI NO EXISTE
f2 = 2
f3 = 2
With H1
For f1 = 2 To .Cells(100000, 1).End(xlUp).Row
' retencion
H2.Cells(f2, 1) = Trim$(CStr(.Cells(f1, 5))) ' codigo cliente
H2.Cells(f2, 2) = Trim$(.Cells(f1, 7)) ' nombre cliente
H2.Cells(f2, 3) = .Cells(f1, 1) ' numero tarjeta
H2.Cells(f2, 4) = Trim$(.Cells(f1, 6)) ' tipo tarjeta
H2.Cells(f2, 5) = Trim$(.Cells(f1, 2)) ' abogado
H2.Cells(f2, 6) = .Cells(f1, 3) ' saldo abogado
H2.Cells(f2, 7) = Trim$(.Cells(f1, 4)) ' numero impagos
Select Case .Cells(f1, 16)
Case 4, 5, 6 ' retencion
H2.Cells(f2, 8) = "Retencion"
Case Else ' recuperacion
H2.Cells(f2, 8) = "Recuperacion"
End Select
.Range(.Cells(f1, 12), .Cells(f1, 47)).Copy
H2.Range(H2.Cells(f2, 9), H2.Cells(f2, 44)).PasteSpecial (xlPasteValues)
f2 = f2 + 1
Next
End With
' borrar filas duplicadas
' ordenar
MsgBox "he finalizado el trabajo" & vbCrLf & "Tiempo empleado: " & Timer() - T1
End Sub