Control en Excel vencimiento facturas a cobrar mediante Excel y mediante VBA.
VBA para el Control de vencimientos ha sido posible gracias a que recientemente se ha puesto en contacto conmigo un seguidor del blog, Ramiro Hernández, que ha confeccionado con programación VBA el ejercicio Control en Excel vencimiento facturas a cobrar en Excel y generosamente comparte con todos nosotros.
Según nos comenta Ramiro Hernández: «En este artículo intento mostrar el código VBA para un conjunto de soluciones propuestas por Yolanda Cuesta para Excel, en el artículo cuyo link es este.»
El mismo ejercicio resuelto mediante código escrito en VBA y compartido altruistamente por Ramiro:
Para calcular FECHA DE VENCIMIENTO:
Sub Calcular_FechaVencimiento()
Dim oHoja As Worksheet
Dim i As Integer
Set oHoja = ThisWorkbook.Worksheets(1)
For i = 6 To 25
oHoja.Cells(i, 10).Value = oHoja.Cells(i, 2).Value + oHoja.Cells(i, 9).Value
Next i
End Sub
Para calcular SITUACION DE HOY:
a) Mediante “escritura” de la fórmula Excel en la celda correspondiente
=SI(K7>0;SI(HOY()>J7;”RECLAMAR”;”ESTA EN PLAZO”);”COBRADA”)
Sub Calcular_SituacionHoy_V1()
Dim oHoja As Worksheet
Dim oRange As Range
Dim i As Integer
Dim sFormula As String
Set oHoja = ThisWorkbook.Worksheets(1)
If oHoja.Cells(6, 10).Value = «» Then
MsgBox «Antes de esta operación, debe calcular la FECHA DE VENCIMIENTO …», _
vbOKOnly, «Ramiro Hernandez Alonso»
Exit Sub
End If
For i = 6 To 25
sFormula = «=IF(K» & i & «>0,IF(TODAY()>J» & i & «,» & Chr(34) & _
«RECLAMAR» & Chr(34) & «,» & Chr(34) & «ESTA EN PLAZO» & _
Chr(34) & «),» & Chr(34) & «COBRADA» & Chr(34) & «)»
oHoja.Cells(i, 12).Value = sFormula
Next i
For i = 6 To 25
Set oRange = oHoja.Cells(i, 12)
oRange.Select
Call FijarColorFondoSinRelleno
If oHoja.Cells(i, 12).Value = «RECLAMAR» Then
Set oRange = oHoja.Cells(i, 12)
oRange.Select
Call FijarColorFondoNaranja
End If
Next
End Sub
b) Mediante la obtención del resultado en la celda correspondiente
Sub Calcular_SituacionHoy_V2()
Dim oHoja As Worksheet
Dim oRange As Range
Dim i As Integer
Set oHoja = ThisWorkbook.Worksheets(1)
If oHoja.Cells(6, 10).Value = «» Then
MsgBox «Antes de esta operación, debe calcular la FECHA DE VENCIMIENTO …», _
vbOKOnly, «Ramiro Hernandez Alonso»
Exit Sub
End If
For i = 6 To 25
Set oRange = oHoja.Cells(i, 12)
oRange.Select
Call FijarColorFondoSinRelleno
If oHoja.Cells(i, 11).Value > 0 Then
If Now > oHoja.Cells(i, 10).Value Then
oHoja.Cells(i, 12).Value = «RECLAMAR»
Set oRange = oHoja.Cells(i, 12)
oRange.Select
Call FijarColorFondoNaranja
Else
oHoja.Cells(i, 12).Value = «ESTA EN PLAZO»
End If
Else
oHoja.Cells(i, 12).Value = «COBRADA»
End If
Next i
End Sub
Para calcular las ACCIONES:
a) Mediante “escritura” de la fórmula Excel en la celda correspondiente
=SI(L7= “RECLAMAR”;”LLAMAR POR TELÉFONO y ENVIAR EMAIL”;”OK”)
Sub Definir_Acciones_V1()
Dim oHoja As Worksheet
Dim oRange As Range
Dim i As Integer
Set oHoja = ThisWorkbook.Worksheets(1)
If oHoja.Cells(6, 12).Value = «» Then
MsgBox «Antes de esta operación, debe calcular la SITUACION DE HOY …», _
vbOKOnly, «Ramiro Hernandez Alonso»
Exit Sub
End If
For i = 6 To 25
oHoja.Cells(i, 13).Value = «=IF(L» & i & «=» & Chr(34) & «RECLAMAR» & _
Chr(34) & «,» & Chr(34) & _
«Llamar por Teléfono y enviar mail» & Chr(34) & _
«,» & Chr(34) & «Ok» & Chr(34) & «)»
Next i
End Sub
b) Mediante la obtención del resultado en la celda correspondiente
Sub Definir_Acciones_V2()
Dim oHoja As Worksheet
Dim oRange As Range
Dim i As Integer
Set oHoja = ThisWorkbook.Worksheets(1)
If oHoja.Cells(6, 12).Value = «» Then
MsgBox «Antes de esta operación, debe calcular la SITUACION DE HOY …», _
vbOKOnly, «Ramiro Hernandez Alonso»
Exit Sub
End If
For i = 6 To 25
If oHoja.Cells(i, 12).Value = «RECLAMAR» Then
oHoja.Cells(i, 13).Value = «Llamar por Teléfono y enviar mail»
Else
oHoja.Cells(i, 13).Value = «Ok»
End If
Next i
End Sub
Se ejecutan, además, algunos procedimientos de apoyo VBA para el Control de vencimientos:
Sub FijarColorFondoNaranja()
With Selection.Interior
.Pattern = xlSolid
.PatternColorIndex = xlAutomatic
.Color = 49407
.TintAndShade = 0
.PatternTintAndShade = 0
End With
End Sub
Sub FijarColorFondoSinRelleno()
With Selection.Interior
.Pattern = xlNone
.TintAndShade = 0
.PatternTintAndShade = 0
End With
End Sub
Si quieres tener acceso al archivo Excel con el código descrito e interfaz mediante el uso de botones de formularios, por favor solicitarlo nombrando VBA para el Control de vencimientos por email.
Mi agradecimiento a Ramiro por contactar y ayudarnos a todos compartiendo el recurso que ha creado VBA para el Control de vencimientos.
Finalmente recordarte que para estar al día de todo lo relacionado con Excel, contabilidad y TIC puedes seguirme en las redes sociales:
FACEBOOK– TWITTER– LINKEDIN.

