Está en la página 1de 9

Private Sub CommandButton1_Click()

Dim Fila As Integer


Dim Fila2 As Integer
Dim final As Integer
Dim Final2 As Integer
Dim Registro As Integer
Dim Registro2 As Integer
Dim objExcel As Object
Dim SaldoTotal As Integer
Dim NombreArchivo As String
Dim ContarFilas As Double
Dim ContarFilasFilas2 As Double
Dim CodProd As String
Dim FiladelTotal As Integer
Dim ValorSaldo As Double

Set objExcel = Workbooks.Add


objExcel.Activate
NombreArchivo = ActiveWorkbook.Name

'Entradas
For Fila = 1 To 1000
If Hoja3.Cells(Fila, 1) = "" Then
final = Fila - 1
Exit For
End If
Next
'Salidas
For Fila2 = 1 To 1000
If Hoja4.Cells(Fila2, 1) = "" Then
Final2 = Fila2 - 1
Exit For
End If
Next

CodProd = Me.ComboBox1

'Establecer datos del producto consultado

ContarFilas = 9
' Asignar el CodProd (cdigo de producto) para el reporte
Application.Workbooks(NombreArchivo).Worksheets(1).Cells(1, 1) =
"DETALLE DE MOVIMIENTOS DE " & UCase(Me.txt_Nombre)
Application.Workbooks(NombreArchivo).Worksheets(1).Cells(3, 2) = CodProd

For Fila = 1 To 1000


If Hoja2.Cells(Fila, 1) = CodProd Then

Application.Workbooks(NombreArchivo).Worksheets(1).Cells(4, 2) =
Hoja2.Cells(Fila, 2)
Application.Workbooks(NombreArchivo).Worksheets(1).Cells(5, 2) =
Hoja2.Cells(Fila, 3)
Exit For
End If
Next

For Fila = 1 To 1000


If Hoja5.Cells(Fila, 1) = CodProd Then
Application.Workbooks(NombreArchivo).Worksheets(1).Cells(6, 2) =
Hoja5.Cells(Fila, 3)
ValorSaldo = Hoja5.Cells(Fila, 3)
Exit For
End If
Next

'Entradas
For Registro = 1 To final
If Hoja3.Cells(Registro, 2) = CodProd Then
ContarFilas = ContarFilas + 1
Application.Workbooks(NombreArchivo).Worksheets(1).Cells(ContarFilas, 2) =
Hoja3.Cells(Registro, 1) 'Comprb

Application.Workbooks(NombreArchivo).Worksheets(1).Cells(ContarFilas, 3) =
Hoja3.Cells(Registro, 4) 'Fecha de ingreso
Application.Workbooks(NombreArchivo).Worksheets(1).Cells(ContarFilas, 4) =
Hoja3.Cells(Registro, 5) 'No.Factura
Application.Workbooks(NombreArchivo).Worksheets(1).Cells(ContarFilas, 5) =
Hoja3.Cells(Registro, 6) 'Proveedor
Application.Workbooks(NombreArchivo).Worksheets(1).Cells(ContarFilas, 6) =
Hoja3.Cells(Registro, 8) 'Tipo Entrada
Application.Workbooks(NombreArchivo).Worksheets(1).Cells(ContarFilas, 7) =
Hoja3.Cells(Registro, 7) 'Cant. Entrada
End If
Next

'Salidas
ContarFilasFilas2 = 9

For Registro2 = 1 To Final2


If Hoja4.Cells(Registro2, 2) = CodProd Then
ContarFilasFilas2 = ContarFilasFilas2 + 1
Application.Workbooks(NombreArchivo).Worksheets(1).Cells(ContarFilasFilas2,
8) = Hoja4.Cells(Registro2, 1) 'Comprb
Application.Workbooks(NombreArchivo).Worksheets(1).Cells(ContarFilasFilas2,
9) = Hoja4.Cells(Registro2, 4) 'Fecha de Salida

Application.Workbooks(NombreArchivo).Worksheets(1).Cells(ContarFilasFilas2,
10) = Hoja4.Cells(Registro2, 5) 'No. de Transf
Application.Workbooks(NombreArchivo).Worksheets(1).Cells(ContarFilasFilas2,
11) = Hoja4.Cells(Registro2, 6) 'Destino
Application.Workbooks(NombreArchivo).Worksheets(1).Cells(ContarFilasFilas2,
12) = Hoja4.Cells(Registro2, 8) 'Tipo Salida
Application.Workbooks(NombreArchivo).Worksheets(1).Cells(ContarFilasFilas2,
13) = -Hoja4.Cells(Registro2, 7) 'Cant. Salida
End If
Next

'Determinar el final para colocar el saldo total del producto

For FiladelTotal = 10 To 1000


If
Application.Workbooks(NombreArchivo).Worksheets(1).Cells(FiladelTotal, 7) = ""
And Application.Workbooks(NombreArchivo).Worksheets(1).Cells(FiladelTotal,
13) = "" Then
SaldoTotal = FiladelTotal
Exit For
End If
Next
Application.Workbooks(NombreArchivo).Worksheets(1).Cells(SaldoTotal,
12) = "Saldo"
Application.Workbooks(NombreArchivo).Worksheets(1).Cells(SaldoTotal,
13) = ValorSaldo

'APLICAR FORMATO A TODO EL REPORTE


Unload Me
objExcel.Activate

'Macro para establecer Bordes en reporte y quitar las lneas de cuadrcula


Range(Cells(10, 2), Cells(SaldoTotal, 13)).Select
Selection.Borders(xlDiagonalDown).LineStyle = xlNone
Selection.Borders(xlDiagonalUp).LineStyle = xlNone
With Selection.Borders(xlEdgeLeft)
.LineStyle = xlContinuous
.ThemeColor = 1
.TintAndShade = -0.249946592608417
.Weight = xlThin
End With
With Selection.Borders(xlEdgeTop)
.LineStyle = xlContinuous
.ThemeColor = 1
.TintAndShade = -0.249946592608417
.Weight = xlThin
End With
With Selection.Borders(xlEdgeBottom)
.LineStyle = xlContinuous
.ThemeColor = 1

.TintAndShade = -0.249946592608417
.Weight = xlThin
End With
With Selection.Borders(xlEdgeRight)
.LineStyle = xlContinuous
.ThemeColor = 1
.TintAndShade = -0.249946592608417
.Weight = xlThin
End With
With Selection.Borders(xlInsideVertical)
.LineStyle = xlContinuous
.ThemeColor = 1
.TintAndShade = -0.249946592608417
.Weight = xlThin
End With
With Selection.Borders(xlInsideHorizontal)
.LineStyle = xlContinuous
.ThemeColor = 1
.TintAndShade = -0.249946592608417
.Weight = xlThin
End With
Range("A3").Select
ActiveWindow.DisplayGridlines = False

'Macro para formatear el saldo


Range(Cells(SaldoTotal, 12), Cells(SaldoTotal, 13)).Select
Selection.Font.Bold = True
Selection.Borders(xlDiagonalDown).LineStyle = xlNone
Selection.Borders(xlDiagonalUp).LineStyle = xlNone
With Selection.Borders(xlEdgeLeft)
.LineStyle = xlContinuous
.Weight = xlMedium
.ColorIndex = xlAutomatic
End With
With Selection.Borders(xlEdgeTop)
.LineStyle = xlContinuous
.Weight = xlMedium
.ColorIndex = xlAutomatic
End With
With Selection.Borders(xlEdgeBottom)
.LineStyle = xlContinuous
.Weight = xlMedium
.ColorIndex = xlAutomatic
End With
With Selection.Borders(xlEdgeRight)
.LineStyle = xlContinuous
.Weight = xlMedium
.ColorIndex = xlAutomatic
End With

'Llamar Macro para dar formato al reporte


Call Formatear_Reporte

También podría gustarte