Está en la página 1de 19

Funciones - 1

Public LineaTraza As Long

Public Sub Integrar()


Dim ULOrigen, ULDestino As Long 'Ultimas líneas de origen y destino
Dim Origen, Destino As Worksheet
Set Origen = Hoja28
Set Destino = Hoja36

'Calcula las últimas líneas de ambas hojas


ULDestino = 5
ULOrigen = 20

'Copia
Origen.Activate
Origen.Range(Origen.Cells(6, 2), Origen.Cells(ULOrigen, 70)).Copy

'Pega
Destino.Activate
Destino.Cells(5, 1).PasteSpecial xlPasteAll
Destino.Cells(1, 1).Select
Hoja32.Activate
'Vacía
Set Origen = Nothing
Set Destino = Nothing

End Sub

Public Function Añadir(ByVal C As String, L As Integer) As String 'C es la cadena y L es el largo q


ue tiene que tener la cadena devuelta con espacios
Dim LargoRecibido, Espacios As Long
LargoRecibido = Len(C)
Espacios = L - LargoRecibido
If LargoRecibido < L Then
Añadir = Space(Espacios) & C 'Añade espacios a la izquierda
Else
Añadir = Right(C, L)
End If
End Function

Public Function AñadirDcha(ByVal C As String, L As Integer) As String 'C es la cadena y L es el lar


go que tiene que tener la cadena devuelta con espacios
Dim LargoRecibido, Espacios As Long
LargoRecibido = Len(C)
Espacios = L - LargoRecibido
If LargoRecibido < L Then
AñadirDcha = C & Space(Espacios) 'Añade espacios a la derecha
Else
AñadirDcha = Left(C, L)
End If
End Function
Public Function Empalmar(Cadenas() As String) As String
For Each n In Cadenas
Empalmar = Empalmar & n
Next n
End Function

Public Sub EscribeTraza(Cadena As String)


LineaTraza = LineaTraza + 1
Worksheets("Traza").Cells(LineaTraza, 1) = Cadena

End Sub
Public Sub EscribeTrazaLC(Cadena As String, ByVal L As Long, ByVal C As Integer) 'L es la línea y C
la columna

LineaTraza = LineaTraza + 1
Worksheets("Traza").Cells(LineaTraza, 1) = Cadena & " " & Replace(Cells(L, C).Address, "$", "")
& "."

End Sub
Public Sub ReseteaTraza()
LineaTraza = 0
Worksheets("Traza").Range("A1:IV" & Rows.Count).ClearContents
End Sub
Public Function NZ(Valor As Variant, Conversión As Variant) As Variant 'Convierte un vacío o un nul
l en un valor numérico
If Valor = "" Or IsNull(Valor) Or IsEmpty(Valor) Then
Funciones - 2

NZ = Conversión
Else
NZ = Valor
End If
End Function
'PROPIEDAD DE ALFREDO GOMEZ GRANDE 51669937T
'Œê¥î†]}Ö’Æf™¹½”Æ’w‘ålà™{™¤¼ˆµß’¨¹Ø}-¡©œÓ¹ÀƒÇ̃Æ[°Š ¨Ÿ§·ªÆÂÆ Þ½§Ø¸ÃÝåÆëÀ¶ÁºÞ¾à
Globales - 1

Public sentEliminar As String


Hoja28 - 1

Private Sub CommandButton2_Click()


RevisarCuadres
End Sub

Private Sub CommandButton1_Click()


Generación
End Sub

Sub RevisarCuadres()
Dim Linea, Columna, TotLinea, LineaConfFact, LineaConfIVA As Long
Dim Debe, Haber, DebeSuma, HaberSuma As Currency
Dim OkRaiz, OkClaveIVA As Boolean

'Cuenta las líneas para poner el porcentaje.

TotLinea = 6
Linea = 6
ReseteaContadores

Do Until Cells(TotLinea, 2).Value = ""


TotLinea = TotLinea + 1
Loop

EscribeTraza ("Revisión de asientos iniciada el " & Date & " " & Time)

Do Until Cells(Linea, 2).Value = "" 'BUCLE CAMBIA TIPO DE DATOS PARA LA ORDENACIÓN POSTERIOR

For Columna = 2 To 70

Valor = Cells(Linea, Columna).Value

Select Case Columna 'Revisión tipos de datos y cambio del dato de las columnas de orden
ación.

Case 2, 4, 7 To 10, 15 To 19, 21, 25, 27, 39 To 43, 48 To 49, 53, 55, 57, 59, 6
1, 63, 65, 66, 68, 70 'Datos numéricos

If Columna = 4 And Cells(Linea, 12) <> "REGULARIZACI" Then 'En el caso de


la columna 4, si es de IVA debe verificar que existe en la tabla de IVA, y si empieza por 40, 43, e
tc, en la de raices.

If Cells(Linea, 10) <> "" Then ' Si la línea es de IVA


LineaConfFact = 2 'Verificación de la raiz de la contrapar
tida
OkRaiz = False
Do Until Worksheets("Config. Facturas").Cells(LineaConfFac
t, 1) = ""
If Trim(Cells(Linea, 12)) Like Trim(Worksheets("Config
. Facturas").Cells(LineaConfFact, 1)) & "*" Then
OkRaiz = True
Exit Do
End If
LineaConfFact = LineaConfFact + 1
Loop
If Not OkRaiz Then EscribeTraza "No se ha encontrado la co
ntrapartida '" & Trim(Cells(Linea, 12)) & "' entre las raices de cuentas descritas en la hoja 'Conf
ig. Facturas'. Revisar línea " & Cells(Linea, 2) + 6

LineaConfIVA = 2 'Verificación de la clave de IVA.


OkClaveIVA = False
Do Until Worksheets("Config. IVA").Cells(LineaConfIVA, 1)
= ""
If Trim(Cells(Linea, 4)) = Trim(Worksheets("Config. IV
A").Cells(LineaConfIVA, 1)) Then
OkClaveIVA = True
Exit Do
End If
LineaConfIVA = LineaConfIVA + 1
Loop
Hoja28 - 2

If Not OkClaveIVA Then EscribeTraza "No se ha encontrado l


a cuenta de IVA '" & Trim(Cells(Linea, 4)) & "' entre las cuentas descritas en la hoja 'Config. IVA
'. Revisar línea " & Cells(Linea, 2) + 6
End If

End If

If Valor <> "" Then


If Not IsNumeric(Valor) Then
EscribeTraza "Valor no numérico en la línea " & Cells(Linea
, 2) + 6
Else
Select Case Columna 'Ordenación: Cambia el tipo de dato par
a que se ordenen
Case 2
Cells(Linea, Columna) = CLng(Cells(Linea, Columna))
Case 7 To 9
Cells(Linea, Columna) = Round(CCur(Cells(Linea, Col
umna)), 2)
End Select
End If 'If del isnumeric(Valor)
End If 'If del Valor<>""

Case 3, 26, 54, 58, 67 'Fechas

If Valor <> "" And Not IsDate(Valor) Then EscribeTraza "Valor no fecha en la lí
nea " & Cells(Linea, 2) + 6

End Select

Next Columna

EscribeContadores Linea, TotLinea


Linea = Linea + 1

Loop

'AQUÍ ORDENA
'Debe poner dentro del mismo asiento, las partidas al debe primero y luego las del Haber. IMPOR
TANTE REVISAR EL RANGO DE ORDENACIÓN SI SE AÑADEN NUEVOS CAMPOS <==================================
===========
OrdenarAsientos

'AQUÍ BUCLE DE ENCONTRAR ASIENTOS DESCUADRADOS


Linea = 6
Debe = 0
Haber = 0
Do Until Cells(Linea, 2).Value = ""

If Cells(Linea, 2) <> "" Then 'Si hay asiento


If IsNumeric(Cells(Linea, 2)) Then 'Si es numérico

'Valores para el cuadre


DebeSuma = Round(NZ(Cells(Linea, 7), 0), 2)
HaberSuma = Round(NZ(Cells(Linea, 8), 0), 2)

Debe = Round(Debe + DebeSuma, 2) 'Total acumulado de Debe en el asiento


Haber = Round(Haber + HaberSuma, 2) 'Idem de Haber

If Cells(Linea, 2) <> Cells(Linea + 1, 2) Then 'Final de asiento


'Salda
If Debe - Haber <> 0 Then ' Descuadre ESCRIBE TRAZA
EscribeTraza "El asiento está descuadrado. Revisar línea " & Cells(
Linea, 2) + 6
End If
'Resetea acumulados
Debe = 0
Hoja28 - 3

Haber = 0
End If
Else 'Si el número de asiento no es numérico
EscribeTraza "Valor no numérico en la celda. Revisar línea " & Cells(Linea, 2) + 6
End If
End If

EscribeContadores Linea, TotLinea


Linea = Linea + 1

Loop

EscribeContadores Linea, TotLinea

EscribeTraza ("Revisión de asientos terminada el " & Date & " " & Time)

Generación

End Sub

Private Sub Generación()

Call MsgBox("Vaya a la página ""Activación"" y siga los pasos que se describen para activarla. Grac
ias. ", vbCritical, "Aplicación no activada")

End Sub

Sub ReseteaContadores()
Cells(3, 2).Value = ""
Cells(3, 3).Value = ""
Cells(3, 4).Value = ""

End Sub

Sub EscribeContadores(ByVal Lin As Long, ByVal Tot As Long)


Cells(3, 2).Value = Lin 'Contador
Cells(3, 3).Value = Lin / Tot
Hoja33.Cells(3, 2).Value = Lin
Hoja33.Cells(3, 3).Value = Lin / Tot
Hoja34.Cells(3, 2).Value = Lin
Hoja34.Cells(3, 3).Value = Lin / Tot
End Sub

Private Sub CommandButton3_Click()


Select Case MsgBox("Atención, va a copiar los datos que haya en la hoja ""Salida Fact-Ext""
" _
& vbCrLf & "a continuación del último asiento que tenga en la hoja actual. V
erifique " _
& vbCrLf & "que no haya números de asiento iguales en ambas hojas. De ser as
í el " _
& vbCrLf & "programa integrará todas las lineas de ambos aisentos en uno sól
oy lo " _
& vbCrLf & "más probable es que descuadre el asiento. " _
& vbCrLf & "" _
& vbCrLf & "¿Desea continuar?" _
, vbYesNo Or vbQuestion Or vbDefaultButton1, "Integrar datos")

Case vbYes
Integrar
Case vbNo
MsgBox "Proceso cancelado", vbInformation, "Atención"
End Select

End Sub
'Sub OLDIntegrar()
'Dim ULOrigen, ULDestino As Long 'Ultimas líneas de origen y destino
'Dim Origen, Destino As Worksheet
Hoja28 - 4

'Set Origen = Worksheets("Salida Fact-Ext")


'Set Destino = ActiveSheet
'
' 'Calcula las últimas líneas de ambas hojas
' ULDestino = Cells(Rows.Count, 2).End(xlUp).Row + 1
' ULOrigen = Worksheets("Salida Fact-Ext").Cells(Rows.Count, 2).End(xlUp).Row
'
' 'Copia
' Origen.Activate
' Origen.Range(Origen.Cells(3, 1), Origen.Cells(ULOrigen, 49)).Copy
'
' 'Pega
' Destino.Activate
' Destino.Range(Cells(ULDestino, 2), Cells(ULDestino, 2)).PasteSpecial xlPasteAll
' Destino.Range(Cells(ULDestino, 2), Cells(ULDestino, 2)).Select
' 'Vacía
' Set Origen = Nothing
' Set Destino = Nothing
'
' 'Informa
' MsgBox "Importación finalizada con éxito.", vbInformation, "Atención"
'
'End Sub

Private Sub CommandButton4_Click()


Select Case MsgBox("Atención, va a borrar todos los datos de la hoja." _
& vbCrLf & "" _
& vbCrLf & "¿Desea continuar?" _
, vbYesNo Or vbExclamation Or vbDefaultButton1, "Integrar datos")

Case vbYes

Range("A6:IV" & Rows.Count).ClearContents

Case vbNo
MsgBox "Proceso cancelado", vbInformation, "Atención"
End Select
End Sub

Sub OrdenarAsientos()

'Ordena IMPORTANTE REVISAR EL RANGO DE ORDENACIÓN SI SE AÑADEN NUEVOS CAMPOS <=================


============================
'Debe poner dentro del mismo aisento, las partidas al debe primero y luego las del Haber.

Range("B6:IV65536").Sort Key1:=Range("B6"), Order1:=xlAscending, Key2:=Range("G6") _


, Order2:=xlDescending, Key3:=Range("H6"), Order3:=xlDescending, Header _
:=xlGuess, OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom _
, DataOption1:=xlSortNormal, DataOption2:=xlSortTextAsNumbers, DataOption3 _
:=xlSortTextAsNumbers

End Sub
Hoja30 - 1

Private Sub CommandButton1_Click()


Generación
End Sub

Private Sub Generación()

Call MsgBox("Vaya a la página ""Activación"" y siga los pasos que se describen para activarla.
Gracias. ", vbCritical, "Aplicación no activada")

End Sub

Private Sub CommandButton2_Click()


Select Case MsgBox("Atención, va a borrar todos los datos de la hoja." _
& vbCrLf & "" _
& vbCrLf & "¿Desea continuar?" _
, vbYesNo Or vbExclamation Or vbDefaultButton1, "Integrar datos")

Case vbYes

Range("A6:AB" & Rows.Count).ClearContents

Case vbNo
MsgBox "Proceso cancelado", vbInformation, "Atención"
End Select
End Sub
Hoja33 - 1

Dim LinD As Long 'Linea de Destino


Dim Asiento As Long
Dim Destino As Worksheet
Dim Fecha As Date
Dim Lin, Tot As Long
Dim TipoFact As String

Private Sub CommandButton1_Click()


RunFacturas
End Sub

Sub RunFacturas()

Tot = 6
Lin = 7
LinD = 6

BorraDestino
TotLineas
ReseteaContador
ReseteaTraza
EscribeTraza "Generación de facturas lanzada el " & Date & " " & Time
Asiento = 1

Set Destino = Hoja28

Do Until Cells(Lin, 2) = "" 'CADA LINEA ES UNA FACTURA. CAMBIO DE LINEA = CAMBIO DE FACTURA = C
AMBIO DE ASIENTO

TipoFact = ""
TipoFact = EmitidaRecibida

'VALORES COMUNES
Comunes
'LINEA DEL TERCERO Asiento/Fecha/Cuenta/Concepto/Documento/Debe/Haber/BaseImp./TipoIVA/%RE/
Contrapartida/DepProyecto
Tercero
'LINEAS BASES IMPONIBLES. Si no hay cuenta, no escribe línea
Bases
'IVA
IVA
'Retenciones
Retencion1
Retencion2
Retencion3

Lin = Lin + 1
Asiento = Asiento + 1
Contador
Loop

Set Destino = Nothing

EscribeTraza ("Generación de facturas terminada el " & Date & " " & Time)

Hoja28.RevisarCuadres 'Lanza el proceso

MsgBox "Generación de facturas terminada. Revise la hoja 'Traza'."


ReseteaContador
Integrar

End Sub
Sub Comunes()
Dim CC As Long
Destino.Cells(LinD, 2) = Asiento 'Asiento
Destino.Cells(LinD, 3) = Cells(Lin, 2) 'Fecha
Destino.Cells(LinD, 5) = Cells(Lin, 56) 'Concepto
Destino.Cells(LinD, 6) = Cells(Lin, 57) 'Documento
Destino.Cells(LinD, 22) = Cells(Lin, 67) 'Inmovilizado
Destino.Cells(LinD, 13) = Cells(Lin, 58) 'Proyecto

For CC = 82 To 87 'Segmentos
Hoja33 - 2

Destino.Cells(LinD, CC - 46).Value = Cells(Lin, CC).Value


Next CC

If Cells(Lin, 2) = "" Or Not IsDate(Cells(Lin, 2)) Then EscribeTrazaLC "Falta la fecha de l


a factura o el dato no es una fecha. Vea la celda ", Lin, 2
End Sub
Sub Tercero()
Dim CT As Long
Comunes
Destino.Cells(LinD, 4) = Cells(Lin, 3) 'Cuenta
Destino.Cells(LinD, 12) = Cells(Lin, 8) 'Contrapartida
If TipoFact = "E" Then Destino.Cells(LinD, 7) = Cells(Lin, 4) 'Importe
If TipoFact = "R" Then Destino.Cells(LinD, 8) = Cells(Lin, 4)
For CT = 62 To 66 'Moneda extranjera
Destino.Cells(LinD, CT - 45).Value = Cells(Lin, CT).Value
Next CT
LinD = LinD + 1

If Cells(Lin, 3) = "" Or Not IsNumeric(Cells(Lin, 3)) Then EscribeTraza "Falta la cuenta de


l tercero o el dato no es numérico. Vea la línea " & Lin
If Cells(Lin, 4) = "" Or Not IsNumeric(Cells(Lin, 4)) Then EscribeTraza "Falta el importe t
otal de la factura o el dato no es numérico. Vea la línea " & Lin

End Sub
Sub Retencion1()
Dim CR As Long
If Cells(Lin, 51) <> "" Then
Comunes
Destino.Cells(LinD, 4) = Cells(Lin, 51) 'Cuenta
Destino.Cells(LinD, 12) = Cells(Lin, 3) 'Contrapartida
If TipoFact = "E" Then Destino.Cells(LinD, 7) = Cells(Lin, 50) 'Importe
If TipoFact = "R" Then Destino.Cells(LinD, 8) = Cells(Lin, 50)
For CT = 62 To 66 'Moneda extranjera
Destino.Cells(LinD, CT - 45).Value = Cells(Lin, CT).Value
Next CT
LinD = LinD + 1

If Cells(Lin, 51) = "" Or Not IsNumeric(Cells(Lin, 51)) Then EscribeTraza "Falta la cue
nta del tercero o el dato no es numérico. Vea la línea " & Lin
If Cells(Lin, 50) = "" Or Not IsNumeric(Cells(Lin, 50)) Then EscribeTraza "Falta el imp
orte total de la factura o el dato no es numérico. Vea la línea " & Lin
End If
End Sub
Sub Retencion2()
Dim CR As Long
If Cells(Lin, 53) <> "" Then
Comunes
Destino.Cells(LinD, 4) = Cells(Lin, 53) 'Cuenta
Destino.Cells(LinD, 12) = Cells(Lin, 3) 'Contrapartida
If TipoFact = "E" Then Destino.Cells(LinD, 7) = Cells(Lin, 52) 'Importe
If TipoFact = "R" Then Destino.Cells(LinD, 8) = Cells(Lin, 52)
For CT = 62 To 66 'Moneda extranjera
Destino.Cells(LinD, CT - 45).Value = Cells(Lin, CT).Value
Next CT
LinD = LinD + 1

If Cells(Lin, 53) = "" Or Not IsNumeric(Cells(Lin, 53)) Then EscribeTraza "Falta la cue
nta del tercero o el dato no es numérico. Vea la línea " & Lin
If Cells(Lin, 52) = "" Or Not IsNumeric(Cells(Lin, 52)) Then EscribeTraza "Falta el imp
orte total de la factura o el dato no es numérico. Vea la línea " & Lin
End If
End Sub
Sub Retencion3()
Dim CR As Long
If Cells(Lin, 55) <> "" Then
Comunes
Destino.Cells(LinD, 4) = Cells(Lin, 55) 'Cuenta
Destino.Cells(LinD, 12) = Cells(Lin, 3) 'Contrapartida
If TipoFact = "E" Then Destino.Cells(LinD, 7) = Cells(Lin, 54) 'Importe
If TipoFact = "R" Then Destino.Cells(LinD, 8) = Cells(Lin, 54)
For CT = 62 To 66 'Moneda extranjera
Destino.Cells(LinD, CT - 45).Value = Cells(Lin, CT).Value
Next CT
LinD = LinD + 1

If Cells(Lin, 55) = "" Or Not IsNumeric(Cells(Lin, 55)) Then EscribeTraza "Falta la cue
Hoja33 - 3

nta del tercero o el dato no es numérico. Vea la línea " & Lin
If Cells(Lin, 54) = "" Or Not IsNumeric(Cells(Lin, 54)) Then EscribeTraza "Falta el imp
orte total de la factura o el dato no es numérico. Vea la línea " & Lin
End If
End Sub

Sub Bases() 'Hace un bucle. Si existe la cuenta procesa el resto del bloque
Dim CB As Long
For CB = 8 To 44
Select Case CB
Case 8, 17, 26, 35, 44
If Cells(Lin, CB) <> "" Then ' Procesa
Comunes
Destino.Cells(LinD, 4) = Cells(Lin, CB) 'Cuenta
Destino.Cells(LinD, 12) = Cells(Lin, 3) 'Contrapartida
If TipoFact = "E" Then Destino.Cells(LinD, 8) = Cells(Lin, CB - 3) 'Importe
If TipoFact = "R" Then Destino.Cells(LinD, 7) = Cells(Lin, CB - 3)

If Cells(Lin, CB) = "" Or Not IsNumeric(Cells(Lin, CB)) Then EscribeTraza "Falt


a la cuenta de la base imponible o el dato no es numérico. Vea la línea " & Lin
If Cells(Lin, CB - 3) = "" Or Not IsNumeric(Cells(Lin, CB - 3)) Then EscribeTra
za "Falta el importe de la base imponible o el dato no es numérico. Vea la línea " & Lin
LinD = LinD + 1
End If
End Select
Next CB

End Sub

Sub IVA()
Dim CI As Long

For CI = 9 To 46

Select Case CI
Case 9, 18, 27, 36, 45 'IVAS SOPORTADOS
If Cells(Lin, CI) <> "" Then ' Procesa
Comunes
Destino.Cells(LinD, 4) = Cells(Lin, CI) 'Cuenta
Destino.Cells(LinD, 7) = Cells(Lin, CI - 3) 'Importe. Un soportado siempre
estará en el Debe
Destino.Cells(LinD, 9) = Cells(Lin, CI - 4) 'Base
Destino.Cells(LinD, 10) = Cells(Lin, CI + 3) 'Tipo

ComunesIVA

If Cells(Lin, CI) = "" Or Not IsNumeric(Cells(Lin, CI)) Then EscribeTrazaLC


"Falta la cuenta de IVA Soportado o el dato no es numérico. Vea la celda ", Lin, CI
If Not CuentaIVA(Cells(Lin, CI)) Then EscribeTrazaLC "La cuenta de IVA Sopo
rtado no se encuentra en la hoja de 'Config.IVA'. Vea la celda ", Lin, CI
If Cells(Lin, CI - 3) = "" Or Not IsNumeric(Cells(Lin, CI - 3)) Then Escrib
eTrazaLC "Falta el importe del IVA Soportado o el dato no es numérico. Vea la celda ", Lin, CI - 3
If Cells(Lin, CI - 4) = "" Or Not IsNumeric(Cells(Lin, CI - 4)) Then Escrib
eTrazaLC "Falta el importe de la base del IVA Soportado o el dato no es numérico. Vea la celda ", L
in, CI - 4
If Cells(Lin, CI + 3) = "" Or Not IsNumeric(Cells(Lin, CI + 3)) Then Escrib
eTrazaLC "Falta el tipo del IVA Soportado o el dato no es numérico. Vea la celda ", Lin, CI + 3
End If

Case 10, 19, 28, 37, 46 'IVAS REPERCUTIDOS

If Cells(Lin, CI) <> "" Then ' Procesa


Comunes
Destino.Cells(LinD, 4) = Cells(Lin, CI) 'Cuenta
Destino.Cells(LinD, 8) = Cells(Lin, CI - 4) 'Importe. El repercutido siempr
e estará en el Haber, independientemente de si es emitida o recibida (en este caso un ISP o una adq
. intracom)
Destino.Cells(LinD, 9) = Cells(Lin, CI - 5) 'Base
Destino.Cells(LinD, 10) = Cells(Lin, CI + 2) 'Tipo

If Cells(Lin, CI + 1) <> "" Then 'Hay cta. de RE


Destino.Cells(LinD, 11) = Cells(Lin, CI + 3) 'Tipo de RE
End If
Hoja33 - 4

ComunesIVA

If Cells(Lin, CI) = "" Or Not IsNumeric(Cells(Lin, CI)) Then EscribeTrazaLC


"Falta la cuenta de del IVA Repercutido o el dato no es numérico. Vea la celda ", Lin, CI
If Not CuentaIVA(Cells(Lin, CI)) Then EscribeTrazaLC "La cuenta de IVA Repe
rcutido no se encuentra en la hoja de 'Config.IVA'. Vea la celda ", Lin, CI
If Cells(Lin, CI - 4) = "" Or Not IsNumeric(Cells(Lin, CI - 4)) Then Escrib
eTrazaLC "Falta el importe del IVA Repercutido o el dato no es numérico. Vea la celda ", Lin, CI -
4
If Cells(Lin, CI - 5) = "" Or Not IsNumeric(Cells(Lin, CI - 5)) Then Escrib
eTrazaLC "Falta el importe de la base del IVA Repercutido o el dato no es numérico. Vea la celda ",
Lin, CI - 5
If Cells(Lin, CI + 2) = "" Or Not IsNumeric(Cells(Lin, CI + 2)) Then Escrib
eTrazaLC "Falta el tipo del IVA Repercutido o el dato no es numérico. Vea la celda ", Lin, CI + 2

'Mira a ver si existe RE


If Cells(Lin, CI + 1) <> "" Then 'Hay cta. de RE
Comunes
Destino.Cells(LinD, 4) = Cells(Lin, CI + 1) 'Cuenta
Destino.Cells(LinD, 12) = Cells(Lin, 3) 'Contrapartida
Destino.Cells(LinD, 8) = Cells(Lin, CI - 3) 'Importe. El repercutido si
empre estará en el Haber, independientemente de si es emitida o recibida (en este caso un ISP o una
adq. intracom)
LinD = LinD + 1

If Cells(Lin, CI + 3) = "" Or Not IsNumeric(Cells(Lin, CI + 3)) Then Es


cribeTrazaLC "Falta el tipo del Recargo de Equivalencia o el dato no es numérico. Vea la celda ", L
in, CI + 3
If Cells(Lin, CI + 1) = "" Or Not IsNumeric(Cells(Lin, CI + 1)) Then Es
cribeTrazaLC "Falta la cuenta del Recargo de Equivalencia o el dato no es numérico. Vea la celda ",
Lin, CI + 1
If Cells(Lin, CI - 3) = "" Or Not IsNumeric(Cells(Lin, CI - 3)) Then Es
cribeTrazaLC "Falta el importe del Recargo de Equivalencia o el dato no es numérico. Vea la celda "
, Lin, CI - 3

End If
End If
End Select

Next CI

End Sub
Sub ComunesIVA()
Dim CCI As Long

Destino.Cells(LinD, 12) = Cells(Lin, 3) 'Contrapartida


Destino.Cells(LinD, 14) = Cells(Lin, 59) 'Serie
Destino.Cells(LinD, 15) = Cells(Lin, 60) 'NumFact

For CCI = 68 To 81
Destino.Cells(LinD, CCI - 45).Value = Cells(Lin, CCI).Value
Next CCI

For CCI = 88 To 94
Destino.Cells(LinD, CCI - 45).Value = Cells(Lin, CCI).Value
Next CCI

'Si no ha especificado nada en el tipo de compra, poner un 1


If Cells(Lin, 95) = "" Then
Destino.Cells(LinD, 50) = 1
Else
Destino.Cells(LinD, 50) = Cells(Lin, 95)
End If

LinD = LinD + 1

End Sub
Sub ReseteaContador()
Cells(3, 2) = ""
Cells(3, 3) = ""
Cells(3, 4) = ""
End Sub
Sub Contador()
Cells(3, 2) = Lin
Hoja33 - 5

Cells(3, 3).Value = Lin / Tot


End Sub
Sub BorraDestino()
Hoja28.Range("A6:IV" & Rows.Count).ClearContents
Hoja29.Range("A1:IV" & Rows.Count).ClearContents
Hoja36.Range("A5:IV" & Rows.Count).ClearContents

End Sub
Function EmitidaRecibida() As String
Dim LicCF As Long
LinCF = 2
Do Until Worksheets("Config. Facturas").Cells(LinCF, 1) = ""
If Cells(Lin, 3) Like Worksheets("Config. Facturas").Cells(LinCF, 1).Value & "*" Then
EmitidaRecibida = Worksheets("Config. Facturas").Cells(LinCF, 2)
Exit Do
End If
LinCF = LinCF + 1
Loop
If EmitidaRecibida = "" Then EscribeTrazaLC "No se ha encontrado la raiz de la cuenta ' " & Cel
ls(Lin, 3) & " ' en la hoja 'Config. Facturas'. Revise la celda ", Lin, 3
End Function
Function CuentaIVA(Cuenta As String) As Boolean
Dim L As Long 'Línea de la hoja de configuración de IVA

L = 2 'Verificación de la clave de IVA.

Do Until Hoja19.Cells(L, 1) = ""


If Cuenta = Hoja19.Cells(L, 1) Then
CuentaIVA = True
Exit Do
End If
L = L + 1
Loop

End Function

Sub TotLineas()
Do Until Cells(Tot, 2).Value = ""
Tot = Tot + 1
Loop

End Sub

Private Sub CommandButton2_Click()


Select Case MsgBox("Atención, va a borrar todos los datos de la hoja." _
& vbCrLf & "" _
& vbCrLf & "¿Desea continuar?" _
, vbYesNo Or vbExclamation Or vbDefaultButton1, "Integrar datos")

Case vbYes

Range("A7:CQ" & Rows.Count).ClearContents

Case vbNo
MsgBox "Proceso cancelado", vbInformation, "Atención"
End Select

End Sub
Hoja34 - 1

Dim LinD As Long 'Linea de Destino


Dim Asiento As Long
Dim Destino As Worksheet
Dim Fecha As Date
Dim Lin As Long

Private Sub CommandButton1_Click()


RunExtracto
End Sub

Sub RunExtracto()

Lin = 7
LinD = 6
Asiento = 1

BorraDestino
ReseteaContador
ReseteaTraza

EscribeTraza "Generación de extracto lanzada el " & Date & " " & Time

If Not IsNumeric(Cells(3, 4)) Or Cells(3, 4) = "" Then EscribeTrazaLC "Falta la cuenta del banc
o o el dato no es numérico. Vea la celda ", 3, 4

Set Destino = Hoja28

Do Until Cells(Lin, 2) = ""


PrimeraLinea
SegundaLinea
Contador
Lin = Lin + 1
Asiento = Asiento + 1
Loop
Set Destino = Nothing

EscribeTraza ("Generación de extracto terminada el " & Date & " " & Time)
Hoja28.RevisarCuadres 'Lanza el proceso
MsgBox "Generación de Extracto terminado. Revise la hoja 'Traza'.", vbInformation, "Atención"
ReseteaContador
Integrar

End Sub
Sub PrimeraLinea()
Comunes
Destino.Cells(LinD, 4) = Cells(Lin, 4) 'Cuenta del tercero
If Cells(Lin, 3) > 0 Then 'Estamos en la línea del tercero, así que si es un cobro (positivo),
irá en el Haber
Destino.Cells(LinD, 8) = Cells(Lin, 3)
Else
Destino.Cells(LinD, 7) = Cells(Lin, 3) * -1
End If

LinD = LinD + 1

If Not IsDate(Cells(Lin, 2)) Then EscribeTrazaLC "Falta la fecha del movimiento o el dato no es
una fecha. Vea la celda ", Lin, 2
If Not IsNumeric(Cells(Lin, 3)) Or Cells(Lin, 3) = "" Then EscribeTrazaLC "Falta el importe del
movimiento o el dato no es numérico. Vea la celda ", Lin, 3
If Not IsNumeric(Cells(Lin, 4)) Or Cells(Lin, 4) = "" Then EscribeTrazaLC "Falta la cuenta del
movimiento o el dato no es numérico. Vea la celda ", Lin, 4

End Sub
Sub SegundaLinea()
Comunes
Destino.Cells(LinD, 4) = Cells(3, 4) 'Cuenta del banco
If Cells(Lin, 3) > 0 Then 'Estamos en la línea del banco, así que si es un cobro (positivo), ir
á en el Debe
Destino.Cells(LinD, 7) = Cells(Lin, 3)
Else
Destino.Cells(LinD, 8) = Cells(Lin, 3) * -1
End If
LinD = LinD + 1
Hoja34 - 2

End Sub

Sub Comunes()
Dim CC As Long

Destino.Cells(LinD, 2) = Asiento 'Asiento


Destino.Cells(LinD, 3) = Cells(Lin, 2) 'Fecha
Destino.Cells(LinD, 5) = Cells(Lin, 5) 'Concepto
Destino.Cells(LinD, 6) = Cells(Lin, 6) 'Documento
Destino.Cells(LinD, 13) = Cells(Lin, 7) 'Proyecto

For CC = 8 To 12 'Moneda Extranjera


Destino.Cells(LinD, CC + 9) = Cells(Lin, CC)
Next CC

For CC = 13 To 14 'Segmentos
Destino.Cells(LinD, CC + 24) = Cells(Lin, CC)
Next CC

Destino.Cells(LinD, 16) = Cells(Lin, 15)

End Sub

Sub ReseteaContador()
Cells(3, 2) = ""
Cells(3, 3) = ""
End Sub
Sub Contador()
Cells(3, 2) = Lin
End Sub
Sub BorraDestino()
Hoja28.Range("A6:IV" & Rows.Count).ClearContents
Hoja29.Range("A1:IV" & Rows.Count).ClearContents
Hoja36.Range("A5:IV" & Rows.Count).ClearContents
End Sub

Private Sub CommandButton2_Click()

Select Case MsgBox("Atención, va a borrar todos los datos de la hoja." _


& vbCrLf & "" _
& vbCrLf & "¿Desea continuar?" _
, vbYesNo Or vbExclamation Or vbDefaultButton1, "Integrar datos")

Case vbYes

Range("A6:O" & Rows.Count).ClearContents

Case vbNo
MsgBox "Proceso cancelado", vbInformation, "Atención"
End Select

End Sub
Shrink - 1

Option Explicit
Sub SHRINK_EXCEL_FILE_SIZE()

Dim WSheet As Worksheet


Dim CSheet As String 'New Worksheet
Dim OSheet As String 'Old WorkSheet
Dim Col As Long
Dim ECol As Long 'Last Column
Dim lRow As Long
Dim BRow As Long 'Last Row
Dim Pic As Object

For Each WSheet In Worksheets

WSheet.Activate
'Put the sheets in a variable to make it easy to go back and forth
CSheet = WSheet.Name

'Rename the sheet to its name with _Delete at the end


OSheet = CSheet & "_X"
WSheet.Name = OSheet
Debug.Print OSheet

'Add a new sheet and call it the original sheets name


Sheets.Add
ActiveSheet.Name = CSheet
Sheets(OSheet).Activate

'Find the bottom cell of data on each column and find the further row
For Col = 1 To Columns.Count 'Find the actual last bottom row
If Cells(Rows.Count, Col).End(xlUp).Row > BRow Then
BRow = Cells(Rows.Count, Col).End(xlUp).Row
End If
Next

Debug.Print BRow

'Find the end cell of data on each row that has data and find the furthest one
For lRow = 1 To BRow 'Find the actual last right column
If Cells(lRow, Columns.Count).End(xlToLeft).Column > ECol Then
ECol = Cells(lRow, Columns.Count).End(xlToLeft).Column
End If
Next

Debug.Print ECol

'Copy the REAL set of data


Range(Cells(1, 1), Cells(BRow, ECol)).Copy
Sheets(CSheet).Activate

Debug.Print "Copied real set of data"

' Paste Every Thing


Range("A1").PasteSpecial xlPasteAll
Debug.Print "Pasted Everything"

' Paste Column Widths


'Range("A1").PasteSpecial xlPasteColumnWidths

Sheets(OSheet).Activate

For Each Pic In ActiveSheet.Pictures


Pic.Copy
Sheets(CSheet).Paste
Sheets(CSheet).Pictures(Pic.Index).Top = Pic.Top
Sheets(CSheet).Pictures(Pic.Index).Left = Pic.Left
Debug.Print "Pic copied"
Next Pic

Sheets(CSheet).Activate

'Reset the variable for the next sheet


BRow = 0
Shrink - 2

ECol = 0

Next WSheet

' Since, Excel will automatically replace the sheet references for you on your formulas,
' the below part puts them back.
' This is done with a simple replace, replacing _Delete with nothing
For Each WSheet In Worksheets
WSheet.Activate
Cells.Replace "_Delete", ""
Next WSheet

'Roll through the sheets and delete the original fat sheets
For Each WSheet In Worksheets
If Not Len(Replace(WSheet.Name, "_Delete", "")) = Len(WSheet.Name) Then
Application.DisplayAlerts = False
WSheet.Delete
Application.DisplayAlerts = True
End If
Next
End Sub
ThisWorkbook - 1

Private Sub Workbook_BeforeClose(Cancel As Boolean)


'ThisWorkbook.Save
End Sub

Private Sub Workbook_Open()

UserForm1.Show

End Sub
UserForm1 - 1

Private Sub CommandButton1_Click()


UserForm1.Hide

End Sub

Private Sub Label8_Click()

End Sub

'---------------------------------------------------------------------------------------
' Procedure : Label7_Click
' Author : ALFREDO
' Date : 06/08/2010
' Purpose :
'---------------------------------------------------------------------------------------
'
Private Sub Label7_Click()

End Sub

También podría gustarte