Te anexo el código para encontrar la última fila
'Informe por Cliente/Destino
Private Sub ComboBox1_Enter()
Dim i As Double
Dim final As Double
Dim tareas As String
'Muestra Razon social del proveedor
'For i = 2 To 30000
'If Hoja3.Cells(i, 4) = "" Then 'Columna D Hoja Salidas
'final = i - 1
'Exit For
'End If
'Next
final = Hoja3.Range("D" & Rows.Count).End(xlUp).Row
'Muestra Razon social del proveedor
For i = 2 To final
tareas = Hoja3.Cells(i, 4)
ComboBox1.AddItem (tareas)
Next
End Sub
Private Sub CommandButton1_Click()
Application.ScreenUpdating = False
Dim nuevo As Object
Dim i As Integer
Dim H As Integer
Dim L As Integer
Dim m As Integer
Dim j As Integer
Dim T As Integer
Dim FINALTOTAL As Integer
Dim final As Integer
Dim FINAL2 As Integer
Dim ORIGEN As String
Dim SALDO As Double
Dim VALOR As String
Dim CONTAR As Double
Dim CONTAR1 As Double
Set nuevo = Workbooks.Add
nuevo.Activate
ORIGEN = ActiveWorkbook.Name
'For i = 1 To 30000
''SALIDAS
'If Hoja3.Cells(i, 4) = "" Then 'Columna D Hoja salidas
'final = i - 1
'Exit For
'End If
'Next
final = Hoja3.Range("D" & Rows.Count).End(xlUp).Row
VALOR = Informe_por_Cliente.ComboBox1
' SALIDAS
CONTAR = 10
' ASIGNAR VALORES PARA EL INFORME
Application.Workbooks(ORIGEN).Worksheets(1).Cells(1, 1) = "INFORME SALIDAS POR CLIENTE/DESTINO"
Application.Workbooks(ORIGEN).Worksheets(1).Cells(4, 2) = VALOR 'Descripcion del Cliente
For L = 1 To final
If Hoja3.Cells(L, 5) = VALOR Then
Application.Workbooks(ORIGEN).Worksheets(1).Cells(4, 4) = Hoja3.Cells(L, 4) 'Razon social del proveedor
Exit For
End If
Next
For j = 1 To final 'la varible guardó última fila de hoja salidas
If Hoja3.Cells(j, 4) = VALOR Then
CONTAR = CONTAR + 1
'funciona salidas
Application.Workbooks(ORIGEN).Worksheets(1).Cells(CONTAR, 2) = Hoja3.Cells(j, 1) 'Codigo Item
Application.Workbooks(ORIGEN).Worksheets(1).Cells(CONTAR, 3) = Hoja3.Cells(j, 2) 'Descricpion Item
Application.Workbooks(ORIGEN).Worksheets(1).Cells(CONTAR, 4) = Hoja3.Cells(j, 3) 'Cantidad
Application.Workbooks(ORIGEN).Worksheets(1).Cells(CONTAR, 5) = Hoja3.Cells(j, 5) 'Fecha Salida
Application.Workbooks(ORIGEN).Worksheets(1).Cells(CONTAR, 6) = Hoja3.Cells(j, 6) 'No de documento
Application.Workbooks(ORIGEN).Worksheets(1).Cells(CONTAR, 7) = Hoja3.Cells(j, 7) 'Valor
End If
Next
'Formatos
Range("A1:G1").Select
With Selection
.HorizontalAlignment = xlCenter
.VerticalAlignment = xlBottom
.WrapText = False
.Orientation = 0
.AddIndent = False
.IndentLevel = 0
.ShrinkToFit = False
.ReadingOrder = xlContext
.MergeCells = False
End With
Selection.Merge
With Selection
.HorizontalAlignment = xlLeft
.VerticalAlignment = xlBottom
.WrapText = False
.Orientation = 0
.AddIndent = False
.IndentLevel = 0
.ShrinkToFit = False
.ReadingOrder = xlContext
.MergeCells = True
End With
With Selection.Interior
.ColorIndex = 10
.Pattern = xlSolid
End With
Selection.Font.ColorIndex = 2
Selection.Font.Bold = True
Range("A4").Select
ActiveCell.FormulaR1C1 = "CLIENTE / DESTINO"
Range("B5:F5").Select
With Selection
.HorizontalAlignment = xlCenter
.VerticalAlignment = xlBottom
.WrapText = False
.Orientation = 0
.AddIndent = False
.IndentLevel = 0
.ShrinkToFit = False
.ReadingOrder = xlContext
.MergeCells = False
End With
Selection.Merge
With Selection
.HorizontalAlignment = xlLeft
.VerticalAlignment = xlBottom
.WrapText = False
.Orientation = 0
.AddIndent = False
.IndentLevel = 0
.ShrinkToFit = False
.ReadingOrder = xlContext
.MergeCells = True
End With
Range("B4:F4").Select
With Selection
.HorizontalAlignment = xlCenter
.VerticalAlignment = xlBottom
.WrapText = False
.Orientation = 0
.AddIndent = False
.IndentLevel = 0
.ShrinkToFit = False
.ReadingOrder = xlContext
.MergeCells = False
End With
Selection.Merge
With Selection
.HorizontalAlignment = xlLeft
.VerticalAlignment = xlBottom
.WrapText = False
.Orientation = 0
.AddIndent = False
.IndentLevel = 0
.ShrinkToFit = False
.ReadingOrder = xlContext
.MergeCells = True
End With
Range("B3:F3").Select
With Selection
.HorizontalAlignment = xlCenter
.VerticalAlignment = xlBottom
.WrapText = False
.Orientation = 0
.AddIndent = False
.IndentLevel = 0
.ShrinkToFit = False
.ReadingOrder = xlContext
.MergeCells = False
End With
Selection.Merge
With Selection
.HorizontalAlignment = xlLeft
.VerticalAlignment = xlBottom
.WrapText = False
.Orientation = 0
.AddIndent = False
.IndentLevel = 0
.ShrinkToFit = False
.ReadingOrder = xlContext
.MergeCells = True
End With
Range("B6:F6").Select
With Selection
.HorizontalAlignment = xlCenter
.VerticalAlignment = xlBottom
.WrapText = False
.Orientation = 0
.AddIndent = False
.IndentLevel = 0
.ShrinkToFit = False
.ReadingOrder = xlContext
.MergeCells = False
End With
Selection.Merge
With Selection
.HorizontalAlignment = xlLeft
.VerticalAlignment = xlBottom
.WrapText = False
.Orientation = 0
.AddIndent = False
.IndentLevel = 0
.ShrinkToFit = False
.ReadingOrder = xlContext
.MergeCells = True
End With
'Encabezados del informe
Range("B8").Select
ActiveCell.FormulaR1C1 = ""
Range("B9").Select
ActiveCell.FormulaR1C1 = "CODIGO ITEM"
Range("C9").Select
ActiveCell.FormulaR1C1 = "DESCRIPCION"
Range("D9").Select
ActiveCell.FormulaR1C1 = "CANTIDAD"
Range("E9").Select
ActiveCell.FormulaR1C1 = "F.SALIDA"
Range("F9").Select
ActiveCell.FormulaR1C1 = "No. DCMTO"
Range("G9").Select
ActiveCell.FormulaR1C1 = "VALOR"
Range("B8:G8").Select
With Selection
.HorizontalAlignment = xlCenter
.VerticalAlignment = xlBottom
.WrapText = False
.Orientation = 0
.AddIndent = False
.IndentLevel = 0
.ShrinkToFit = False
.ReadingOrder = xlContext
.MergeCells = False
End With
Selection.Merge
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
Selection.Borders(xlInsideVertical).LineStyle = xlNone
ActiveCell.FormulaR1C1 = "SALIDAS PARA EL CLIENTE/DESTINO SELECCIONADO"
Range("B8:G8").Select
With Selection.Interior
.ColorIndex = 3
.Pattern = xlSolid
End With
Selection.Font.ColorIndex = 2
Selection.Font.Bold = True
Range("B9:G9").Select
Selection.Font.Bold = True
Range("B9:G9").Select
Selection.Borders(xlDiagonalDown).LineStyle = xlNone
Selection.Borders(xlDiagonalUp).LineStyle = xlNone
With Selection.Borders(xlEdgeLeft)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
With Selection.Borders(xlEdgeTop)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
With Selection.Borders(xlEdgeBottom)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
With Selection.Borders(xlEdgeRight)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
With Selection.Borders(xlInsideVertical)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
Cells.Select
Cells.EntireColumn.AutoFit
Range("A2").Select
'Formato de fecha
Range("E11").Select
Range(Selection, Selection.End(xlDown)).Select
Selection.NumberFormat = "m/d/yyyy"
Range("B11").Select
Informe_por_Cliente.ComboBox1 = ""
'Formato de numero
Range("G11").Select
Range(Selection, Selection.End(xlDown)).Select
Selection.NumberFormat = "#,##0.00"
Range("E10").Select
Unload Me
Unload Informes
Unload Menu_Principal
'Hoja2.Visible = xlSheetVeryHidden
'Hoja3.Visible = xlSheetVeryHidden
'Hoja5.Visible = xlSheetVeryHidden
'Hoja6.Visible = xlSheetVeryHidden
Hoja1.Cells(3, 1) = ""
End Sub.
'S aludos. Dante Amor. Recuerda valorar la respuesta. G racias
.
Avísame cualquier duda
.