Corrección macro que genera problema con variable

Para Dante Amor

Hola de nuevo:

Continuando con las consultas que le he venido formulando, el siguiente formulario a revisar es "Informes", presenta la misma situación del limite de 30000.

El siguiente es el código:

'Informe Stock actual
Private Sub CommandButton1_Click()
Dim nuevo As Object
Dim ORIGEN As String
Dim i As Integer
Dim j As Integer
Dim final As Integer
Dim VALOR As String
Application.ScreenUpdating = False
Set nuevo = Workbooks.Add
nuevo.Activate
ORIGEN = ActiveWorkbook.Name
For i = 1 To 30000
If Hoja6.Cells(i, 1) = "" Then
final = i - 1
Exit For
End If
Next
VALOR = Hoja6.Cells(1, 1)
For j = 1 To final
'Datos para el reporte
Application.Workbooks(ORIGEN).Worksheets(1).Cells(1, 1) = "INFORME STOCK ACTUAL DE TODOS LOS PRODUCTOS"
Application.Workbooks(ORIGEN).Worksheets(1).Cells(j + 2, 1) = Hoja6.Cells(j, 1)  'Código
Application.Workbooks(ORIGEN).Worksheets(1).Cells(j + 2, 2) = Hoja6.Cells(j, 2)  'Descripción
Application.Workbooks(ORIGEN).Worksheets(1).Cells(j + 2, 3) = Hoja6.Cells(j, 4)  'Cantidad
Application.Workbooks(ORIGEN).Worksheets(1).Cells(j + 2, 4) = Hoja6.Cells(j, 5)  'Costo unitario
Application.Workbooks(ORIGEN).Worksheets(1).Cells(j + 2, 5) = Hoja6.Cells(j, 6)  'Costo Total
Next

1 respuesta

Respuesta
2

Te anexo la macro actualizada para obtener la fila final. En la siguiente línea estoy obteniendo la última fila según la columna "A"

    final = Hoja6.Range("A" & Rows.Count).End(xlUp).Row

La macro completa:

Private Sub CommandButton1_Click()
    Application.ScreenUpdating = False
    Set nuevo = Workbooks.Add
    nuevo.Activate
    ORIGEN = ActiveWorkbook.Name
    final = Hoja6.Range("A" & Rows.Count).End(xlUp).Row
    VALOR = Hoja6.Cells(1, 1)
    For j = 1 To final
        'Datos para el reporte
        Application.Workbooks(ORIGEN).Worksheets(1).Cells(1, 1) = "INFORME STOCK ACTUAL DE TODOS LOS PRODUCTOS"
        Application.Workbooks(ORIGEN).Worksheets(1).Cells(j + 2, 1) = Hoja6.Cells(j, 1)  'Código
        Application.Workbooks(ORIGEN).Worksheets(1).Cells(j + 2, 2) = Hoja6.Cells(j, 2)  'Descripción
        Application.Workbooks(ORIGEN).Worksheets(1).Cells(j + 2, 3) = Hoja6.Cells(j, 4)  'Cantidad
        Application.Workbooks(ORIGEN).Worksheets(1).Cells(j + 2, 4) = Hoja6.Cells(j, 5)  'Costo unitario
        Application.Workbooks(ORIGEN).Worksheets(1).Cells(j + 2, 5) = Hoja6.Cells(j, 6)  'Costo Total
    Next
End Sub

.

'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