Generar informe por mes y año con macro
Para Dante Amor
Buen día:
Tengo una macro con la que genero un informe a partir de una base de datos contenida en el archivo que contiene las macros, tengo dificultades cuando el numero de filas con datos supera 3600, creo que es por el tipo de variable que utilizo, pero no he logrado dar con el error, este es el código que utilizo para generar el informe.
De antemano muchas gracias por su constante apoyo.
PD: Le envié al correo el archivo.
'Informe entradas por mes
Private Sub ComboBox1_Enter()
Application.ScreenUpdating = False
Dim i As Double
Dim final As Double
Dim tareas As String
'Muestra el numero del mes
For i = 2 To 30
If Hoja1.Cells(i, 27) = "" Then 'Columna AA hoja Formulario
final = i - 1
Exit For
End If
Next
'Muestra el numero del mes
For i = 2 To final
tareas = Hoja1.Cells(i, 27)
ComboBox1.AddItem (tareas)
Next
End Sub
Private Sub ComboBox2_Enter()
Application.ScreenUpdating = False
Dim i As Double
Dim final As Double
Dim tareas As String
'Muestra el AÑO
For i = 2 To 30
If Hoja1.Cells(i, 30) = "" Then 'Columna AD hoja Formulario
final = i - 1
Exit For
End If
Next
'Muestra el numero del año
For i = 2 To final
tareas = Hoja1.Cells(i, 30)
ComboBox2.AddItem (tareas)
Next
End Sub
Private Sub ComboBox1_Click()
Dim i As Integer
Dim final As Integer
'Muestra la descripcion del mes
For i = 2 To 30
If Hoja1.Cells(i, 27) = "" Then 'Columna AA hoja Formulario
final = i - 1
Exit For
End If
Next
'Muestra la descripcion del mes
For i = 2 To final
If CStr(ComboBox1) = CStr(Hoja1.Cells(i, 27)) Then 'Columna AA hoja Formulario
'Muestra la descripcion del mes
TextBox1 = Hoja1.Cells(i, 28)
Exit For
End If
Next
End Sub
Private Sub CommandButton1_Click()
Dim nuevo As Object
Dim i As Integer
Dim L As Integer
Dim j As Integer
Dim VALOR As String
Dim CONTAR As Double
Dim CONTAR1 As Double
Dim libro1 As String
'Extraer el mes de la hoja entradas
ActiveWorkbook.Unprotect "1717171"
Hoja2.Visible = xlSheetVisible 'Hoja Entradas
Sheets("ENTRADAS").Select
libro1 = ActiveWorkbook.Name
Dim mes As String
ult = Hoja2.Range("A" & Rows.Count).End(xlUp).Row
'Extraer el mes y año de la hoja entradas
For y = 2 To ult
mes = Month(Cells(y, 5)) '5 Indica la columna donde esta la fecha
Hoja2.Unprotect Password = "1717171" 'Hoja entradas
Cells(y, 11) = mes '11 indica la columna donde colocara el No. Del mes
Cells(y, 12) = Year(Cells(y, 5)) 'guarda el año en col 12
Next
Set nuevo = Workbooks.Add
nuevo.Activate
ORIGEN = ActiveWorkbook.Name
For i = 1 To 30000
'ENTRADAS
If Hoja2.Cells(i, 9) = "" Then 'Columna I Hoja Entradas ultima con datos
final = i - 1
Exit For
End If
Next
VALOR = Informe_EA_Mes.ComboBox1
' ENTRADAS
CONTAR = 10 '11
' ASIGNAR VALORES PARA EL INFORME
Application.Workbooks(ORIGEN).Worksheets(1).Cells(1, 1) = "INFORME ENTRADAS POR MES"
Application.Workbooks(ORIGEN).Worksheets(1).Cells(3, 2) = VALOR '3 indica No. De Fila y 2 No. Columna
For L = 1 To 30000
If Hoja1.Cells(L, 27) = VALOR Then
Application.Workbooks(ORIGEN).Worksheets(1).Cells(4, 2) = Hoja1.Cells(L, 28) 'Descricpion del mes
Exit For
End If
Next
For j = 1 To final 'la varible guardó última fila de hoja Entradas
If Hoja2.Cells(j, 11) = VALOR And Hoja2.Cells(j, 12) = Val(ComboBox2) 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
Application.Workbooks(ORIGEN).Worksheets(1).Cells(CONTAR, 6) = Hoja2.Cells(j, 3) 'Cantidad entrada
Application.Workbooks(ORIGEN).Worksheets(1).Cells(CONTAR, 7) = Hoja2.Cells(j, 8) 'Valor
End If
Next