Corrección de macro que presenta problemas

Para Dante Amor.

Hola nuevamente:

Al igual que en la solicitud anterior, solicito de su colaboración con la revisión del formulario Informe_por_Proveedor, me presenta la misma situación de la consulta anterior, el siguiente es el código:

Informe por Proveedor
Private Sub ComboBox1_Enter()
Dim i As Double
Dim final As Double
Dim tareas As String
ComboBox1.BackColor = &H80000005
  For i = 1 To ComboBox1.ListCount
   ComboBox1.RemoveItem 0
    Next i
'Muestra Razon social del proveedor
For i = 2 To 30000
If Hoja7.Cells(i, 3) = "" Then
final = i - 1
Exit For
End If
Next
'Muestra Razon social del proveedor
  For i = 2 To final
  tareas = Hoja7.Cells(i, 3)
  ComboBox1.AddItem (tareas)
  Next
End Sub
Private Sub ComboBox1_Click()
Dim i As Integer
Dim final As Integer
'Muestra nit del proveedor
For i = 2 To 30000
If Hoja7.Cells(i, 3) = "" Then
final = i - 1
Exit For
End If
Next
'Muestra nit del proveedor
For i = 2 To final
If CStr(ComboBox1) = CStr(Hoja7.Cells(i, 3)) Then
'If ComboBox1 = Hoja7.Cells(i, 3) Then
'muestra nit delproveedor
TextBox1 = Hoja7.Cells(i, 2)
Exit For
End If
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
'ENTRADAS
If Hoja2.Cells(i, 4) = "" Then 'Columna D Hoja Entradas
final = i - 1
Exit For
End If
Next
VALOR = Informe_por_Proveedor.ComboBox1
' ENTRADAS
CONTAR = 10
' ASIGNAR VALORES PARA EL INFORME
Application.Workbooks(ORIGEN).Worksheets(1).Cells(1, 1) = "INFORME ENTRADAS POR PROVEEDOR"
Application.Workbooks(ORIGEN).Worksheets(1).Cells(3, 2) = VALOR
For L = 1 To 30000
If Hoja7.Cells(L, 3) = VALOR Then
Application.Workbooks(ORIGEN).Worksheets(1).Cells(3, 2) = Hoja7.Cells(L, 4) 'Nit del proveedor
Application.Workbooks(ORIGEN).Worksheets(1).Cells(4, 3) = Hoja7.Cells(L, 3) 'Razon social del proveedor
Application.Workbooks(ORIGEN).Worksheets(1).Cells(5, 3) = Hoja7.Cells(L, 5) 'Direccion del proveedor
Exit For
End If
Next
For j = 1 To final   'la varible guardó última fila de hoja Entradas
If Hoja2.Cells(j, 4) = VALOR Then
CONTAR = CONTAR + 1
'funciona entradas
Application.Workbooks(ORIGEN).Worksheets(1).Cells(CONTAR, 2) = Hoja2.Cells(j, 6) 'Numero Fra
Application.Workbooks(ORIGEN).Worksheets(1).Cells(CONTAR, 3) = Hoja2.Cells(j, 1) 'Codigo Item
Application.Workbooks(ORIGEN).Worksheets(1).Cells(CONTAR, 4) = Hoja2.Cells(j, 2) 'Descricpion Item
Application.Workbooks(ORIGEN).Worksheets(1).Cells(CONTAR, 5) = Hoja2.Cells(j, 5) 'Fecha Entrada
NumberFormat = "dd/mm/yyyy"
Application.Workbooks(ORIGEN).Worksheets(1).Cells(CONTAR, 6) = Hoja2.Cells(j, 3) 'Cantidad entrada
End If
Next

1 respuesta

Respuesta
1

Para encontrar la última fila no es necesario esto:

For i = 1 To 30000
'ENTRADAS
If Hoja2.Cells(i, 4) = "" Then 'Columna D Hoja Entradas
final = i - 1
Exit For
End If

Para encontrar la última fila puede ser con esto:

    final = Hoja2.Range("D" & Rows. Count).End(xlUp). Row 'columns "D" entradas

Entonces en el "For" podrías algo como esto:

For L = 1 To final

En el otro "For"


Nota: No es necesario declarar variables en VBA. Lee el contenido del siguiente enlace:

Según su función ¿Cómo declarar variables?


.

'S aludos. Dante Amor. Recuerda valorar la respuesta. G racias

.

Avísame cualquier duda

.

Añade tu respuesta

Haz clic para o

Más respuestas relacionadas