90 minutos tarda en ejecutarse una Macro. Necesito reducir este tiempo.

Tengo una macro que tarda más de una hora en ejecutarse y necesito reducir este tiempo.

1 Respuesta

Respuesta
1

¿Y qué hará esa macro?

Algunas ideas:

1- Revisar el peso del libro. Quizás por alguna razón se disparó el tamaño del libro lo que hará que los procesos demoren más de lo normal.

2- Si el libro tiene muchas fórmulas e intentas pasar datos con tu macro, debes pasar a modo de cálculo manual y al finalizar volverlo a automático. Algo así:

    Application.Calculation = xlManual
    'tus instrucciones de pase de datos 
    Application.Calculation = xlAutomatic

3- si copias y pegas filas enteras revisa que no haya objetos  que te los estés llevando también lo que aumentará el peso y tiempo de proceso.

4- En cuanto a la programación revisa que no tengas alguna instrucción que busca el final de rango hacia abajo (End(xlDown)... cuando no hay datos hará que busque hasta la última de LA HOJA. En ese caso debes buscar desde abajo hacia arriba (End(xlUp)

5- Otro detalle a revisar es si estás manipulando datos con formatos condicionales, etc. etc.

Si luego de revisar todos estos detalles el problema persiste tendrás que dejar tu macro escrita aquí y aclara cómo es el proceso.

Elsa,

Mucho gusto saber de ti.

El libro no tiene una sola fórmula pero la macro tiene un bucle For Each... Next i

Y trabaja con If, And, Or y son 98,000 renglones los que tiene que buscar.

Te paso la Macro.

Sub LLENADOEJECUTIVO()
'Macro elaborada por Jorge Cue Perez
Set h1 = Sheets("DB")
Set h2 = Sheets("Ejecutivo")
Msg = MsgBox("Quieres borrar el contenido del reporte ejecutivo?", vbYesNo, "Reporte de Ciclos")
If Msg <> 6 Then
Exit Sub
End If
h2.Range("A2:AM1000000").ClearContents
Dim i As Long
On Error Resume Next
'For i = 1 To Rows.Count
For i = 1 To h1.Cells(Rows.Count, 1).End(xlUp).Row
h2row = h2.Range("A" & Rows.Count).End(xlUp).Row + 1
'Un cliente
If h1.Cells(i, 2) = h1.Cells(i + 1, 2) And Left(h1.Cells(i, 6), 6) = "Planta" And _
(Left(h1.Cells(i + 1, 6), 3) = "Dis" Or Left(h1.Cells(i + 1, 6), 3) = "Bod" Or Left(h1.Cells(i + 1, 6), 3) = "Tek") _
And Left(h1.Cells(i + 2, 6), 6) = "Planta" Then
h2.Cells(h2row, 1) = h1.Cells(i, 1)
h2.Cells(h2row, 2) = h1.Cells(i, 2)
h2.Cells(h2row, 3) = h1.Cells(i, 6)
h2.Cells(h2row, 4) = h1.Cells(i + 1, 6)
If h2.Cells(h2row, 4) <> "" Then
h2.Cells(h2row, 13) = h1.Cells(i, 19)
h2.Cells(h2row, 14) = h1.Cells(i, 20)
h2.Cells(h2row, 15) = h1.Cells(i + 1, 9)
h2.Cells(h2row, 39) = Application.WorksheetFunction.Sum(h2.Cells(h2row, 13), (h2.Cells(h2row, 38)))
End If
End If
'Dos clientes
If h1.Cells(i, 2) = h1.Cells(i + 1, 2) And Left(h1.Cells(i, 6), 6) = "Planta" And _
(Left(h1.Cells(i + 1, 6), 3) = "Dis" Or Left(h1.Cells(i + 1, 6), 3) = "Bod" Or Left(h1.Cells(i + 1, 6), 3) = "Tek") _
And (Left(h1.Cells(i + 2, 6), 3) = "Dis" Or Left(h1.Cells(i + 2, 6), 3) = "Bod" Or Left(h1.Cells(i + 2, 6), 3) = "Tek") _
And Left(h1.Cells(i + 3, 6), 6) = "Planta" Then
h2.Cells(h2row, 1) = h1.Cells(i, 1)
h2.Cells(h2row, 2) = h1.Cells(i, 2)
h2.Cells(h2row, 3) = h1.Cells(i, 6)
h2.Cells(h2row, 4) = h1.Cells(i + 1, 6)
h2.Cells(h2row, 5) = h1.Cells(i + 2, 6)
If h2.Cells(h2row, 5) <> "" Then
h2.Cells(h2row, 13) = h1.Cells(i, 19)
h2.Cells(h2row, 14) = h1.Cells(i, 20)
h2.Cells(h2row, 15) = h1.Cells(i + 1, 9)
h2.Cells(h2row, 16) = h1.Cells(i + 1, 19)
h2.Cells(h2row, 17) = h1.Cells(i + 1, 20)
h2.Cells(h2row, 18) = h1.Cells(i + 2, 9)
h2.Cells(h2row, 39) = Application.WorksheetFunction.Sum(h2.Cells(h2row, 13), (h2.Cells(h2row, 38)))
End If
End If
'tres clientes
If h1.Cells(i, 2) = h1.Cells(i + 1, 2) And Left(h1.Cells(i, 6), 6) = "Planta" And _
(Left(h1.Cells(i + 1, 6), 3) = "Dis" Or Left(h1.Cells(i + 1, 6), 3) = "Bod" Or Left(h1.Cells(i + 1, 6), 3) = "Tek") _
And (Left(h1.Cells(i + 2, 6), 3) = "Dis" Or Left(h1.Cells(i + 2, 6), 3) = "Bod" Or Left(h1.Cells(i + 2, 6), 3) = "Tek") _
And (Left(h1.Cells(i + 3, 6), 3) = "Dis" Or Left(h1.Cells(i + 3, 6), 3) = "Bod" Or Left(h1.Cells(i + 3, 6), 3) = "Tek") _
And Left(h1.Cells(i + 4, 6), 6) = "Planta" Then
h2.Cells(h2row, 1) = h1.Cells(i, 1)
h2.Cells(h2row, 2) = h1.Cells(i, 2)
h2.Cells(h2row, 3) = h1.Cells(i, 6)
h2.Cells(h2row, 4) = h1.Cells(i + 1, 6)
h2.Cells(h2row, 5) = h1.Cells(i + 2, 6)
h2.Cells(h2row, 6) = h1.Cells(i + 3, 6)
If h2.Cells(h2row, 6) <> "" Then
h2.Cells(h2row, 13) = h1.Cells(i, 19)
h2.Cells(h2row, 14) = h1.Cells(i, 20)
h2.Cells(h2row, 15) = h1.Cells(i + 1, 9)
h2.Cells(h2row, 16) = h1.Cells(i + 1, 19)
h2.Cells(h2row, 17) = h1.Cells(i + 1, 20)
h2.Cells(h2row, 18) = h1.Cells(i + 2, 9)
h2.Cells(h2row, 19) = h1.Cells(i + 2, 19)
h2.Cells(h2row, 20) = h1.Cells(i + 2, 20)
h2.Cells(h2row, 21) = h1.Cells(i + 3, 9)
h2.Cells(h2row, 39) = Application.WorksheetFunction.Sum(h2.Cells(h2row, 13), (h2.Cells(h2row, 38)))
End If
End If
'Cuatro clientes
If h1.Cells(i, 2) = h1.Cells(i + 1, 2) And Left(h1.Cells(i, 6), 6) = "Planta" And _
(Left(h1.Cells(i + 1, 6), 3) = "Dis" Or Left(h1.Cells(i + 1, 6), 3) = "Bod" Or Left(h1.Cells(i + 1, 6), 3) = "Tek") _
And (Left(h1.Cells(i + 2, 6), 3) = "Dis" Or Left(h1.Cells(i + 2, 6), 3) = "Bod" Or Left(h1.Cells(i + 2, 6), 3) = "Tek") _
And (Left(h1.Cells(i + 3, 6), 3) = "Dis" Or Left(h1.Cells(i + 3, 6), 3) = "Bod" Or Left(h1.Cells(i + 3, 6), 3) = "Tek") _
And (Left(h1.Cells(i + 4, 6), 3) = "Dis" Or Left(h1.Cells(i + 4, 6), 3) = "Bod" Or Left(h1.Cells(i + 4, 6), 3) = "Tek") _
And Left(h1.Cells(i + 5, 6), 6) = "Planta" Then
h2.Cells(h2row, 1) = h1.Cells(i, 1)
h2.Cells(h2row, 2) = h1.Cells(i, 2)
h2.Cells(h2row, 3) = h1.Cells(i, 6)
h2.Cells(h2row, 4) = h1.Cells(i + 1, 6)
h2.Cells(h2row, 5) = h1.Cells(i + 2, 6)
h2.Cells(h2row, 6) = h1.Cells(i + 3, 6)
h2.Cells(h2row, 7) = h1.Cells(i + 4, 6)
If h2.Cells(h2row, 7) <> "" Then
h2.Cells(h2row, 13) = h1.Cells(i, 19)
h2.Cells(h2row, 14) = h1.Cells(i, 20)
h2.Cells(h2row, 15) = h1.Cells(i + 1, 9)
h2.Cells(h2row, 16) = h1.Cells(i + 1, 19)
h2.Cells(h2row, 17) = h1.Cells(i + 1, 20)
h2.Cells(h2row, 18) = h1.Cells(i + 2, 9)
h2.Cells(h2row, 19) = h1.Cells(i + 2, 19)
h2.Cells(h2row, 20) = h1.Cells(i + 2, 20)
h2.Cells(h2row, 21) = h1.Cells(i + 3, 9)
h2.Cells(h2row, 22) = h1.Cells(i + 3, 19)
h2.Cells(h2row, 23) = h1.Cells(i + 3, 20)
h2.Cells(h2row, 24) = h1.Cells(i + 4, 9)
h2.Cells(h2row, 39) = Application.WorksheetFunction.Sum(h2.Cells(h2row, 13), (h2.Cells(h2row, 38)))
End If
End If
'Cinco clientes
If h1.Cells(i, 2) = h1.Cells(i + 1, 2) And Left(h1.Cells(i, 6), 6) = "Planta" And _
(Left(h1.Cells(i + 1, 6), 3) = "Dis" Or Left(h1.Cells(i + 1, 6), 3) = "Bod" Or Left(h1.Cells(i + 1, 6), 3) = "Tek") _
And (Left(h1.Cells(i + 2, 6), 3) = "Dis" Or Left(h1.Cells(i + 2, 6), 3) = "Bod" Or Left(h1.Cells(i + 2, 6), 3) = "Tek") _
And (Left(h1.Cells(i + 3, 6), 3) = "Dis" Or Left(h1.Cells(i + 3, 6), 3) = "Bod" Or Left(h1.Cells(i + 3, 6), 3) = "Tek") _
And (Left(h1.Cells(i + 4, 6), 3) = "Dis" Or Left(h1.Cells(i + 4, 6), 3) = "Bod" Or Left(h1.Cells(i + 4, 6), 3) = "Tek") _
And (Left(h1.Cells(i + 5, 6), 3) = "Dis" Or Left(h1.Cells(i + 5, 6), 3) = "Bod" Or Left(h1.Cells(i + 5, 6), 3) = "Tek") _
And Left(h1.Cells(i + 6, 6), 6) = "Planta" Then
h2.Cells(h2row, 1) = h1.Cells(i, 1)
h2.Cells(h2row, 2) = h1.Cells(i, 2)
h2.Cells(h2row, 3) = h1.Cells(i, 6)
h2.Cells(h2row, 4) = h1.Cells(i + 1, 6)
h2.Cells(h2row, 5) = h1.Cells(i + 2, 6)
h2.Cells(h2row, 6) = h1.Cells(i + 3, 6)
h2.Cells(h2row, 7) = h1.Cells(i + 4, 6)
h2.Cells(h2row, 8) = h1.Cells(i + 5, 6)
If h2.Cells(h2row, 8) <> "" Then
h2.Cells(h2row, 13) = h1.Cells(i, 19)
h2.Cells(h2row, 14) = h1.Cells(i, 20)
h2.Cells(h2row, 15) = h1.Cells(i + 1, 9)
h2.Cells(h2row, 16) = h1.Cells(i + 1, 19)
h2.Cells(h2row, 17) = h1.Cells(i + 1, 20)
h2.Cells(h2row, 18) = h1.Cells(i + 2, 9)
h2.Cells(h2row, 19) = h1.Cells(i + 2, 19)
h2.Cells(h2row, 20) = h1.Cells(i + 2, 20)
h2.Cells(h2row, 21) = h1.Cells(i + 3, 9)
h2.Cells(h2row, 22) = h1.Cells(i + 3, 19)
h2.Cells(h2row, 23) = h1.Cells(i + 3, 20)
h2.Cells(h2row, 24) = h1.Cells(i + 4, 9)
h2.Cells(h2row, 25) = h1.Cells(i + 4, 19)
h2.Cells(h2row, 26) = h1.Cells(i + 4, 20)
h2.Cells(h2row, 27) = h1.Cells(i + 5, 9)
h2.Cells(h2row, 39) = Application.WorksheetFunction.Sum(h2.Cells(h2row, 13), (h2.Cells(h2row, 38)))
End If
End If
'Seis clientes
If h1.Cells(i, 2) = h1.Cells(i + 1, 2) And Left(h1.Cells(i, 6), 6) = "Planta" And _
(Left(h1.Cells(i + 1, 6), 3) = "Dis" Or Left(h1.Cells(i + 1, 6), 3) = "Bod" Or Left(h1.Cells(i + 1, 6), 3) = "Tek") _
And (Left(h1.Cells(i + 2, 6), 3) = "Dis" Or Left(h1.Cells(i + 2, 6), 3) = "Bod" Or Left(h1.Cells(i + 2, 6), 3) = "Tek") _
And (Left(h1.Cells(i + 3, 6), 3) = "Dis" Or Left(h1.Cells(i + 3, 6), 3) = "Bod" Or Left(h1.Cells(i + 3, 6), 3) = "Tek") _
And (Left(h1.Cells(i + 4, 6), 3) = "Dis" Or Left(h1.Cells(i + 4, 6), 3) = "Bod" Or Left(h1.Cells(i + 4, 6), 3) = "Tek") _
And (Left(h1.Cells(i + 5, 6), 3) = "Dis" Or Left(h1.Cells(i + 5, 6), 3) = "Bod" Or Left(h1.Cells(i + 5, 6), 3) = "Tek") _
And (Left(h1.Cells(i + 6, 6), 3) = "Dis" Or Left(h1.Cells(i + 6, 6), 3) = "Bod" Or Left(h1.Cells(i + 6, 6), 3) = "Tek") _
And Left(h1.Cells(i + 7, 6), 6) = "Planta" Then
h2.Cells(h2row, 1) = h1.Cells(i, 1)
h2.Cells(h2row, 2) = h1.Cells(i, 2)
h2.Cells(h2row, 3) = h1.Cells(i, 6)
h2.Cells(h2row, 4) = h1.Cells(i + 1, 6)
h2.Cells(h2row, 5) = h1.Cells(i + 2, 6)
h2.Cells(h2row, 6) = h1.Cells(i + 3, 6)
h2.Cells(h2row, 7) = h1.Cells(i + 4, 6)
h2.Cells(h2row, 8) = h1.Cells(i + 5, 6)
h2.Cells(h2row, 9) = h1.Cells(i + 6, 6)
If h2.Cells(h2row, 9) <> "" Then
h2.Cells(h2row, 13) = h1.Cells(i, 19)
h2.Cells(h2row, 14) = h1.Cells(i, 20)
h2.Cells(h2row, 15) = h1.Cells(i + 1, 9)
h2.Cells(h2row, 16) = h1.Cells(i + 1, 19)
h2.Cells(h2row, 17) = h1.Cells(i + 1, 20)
h2.Cells(h2row, 18) = h1.Cells(i + 2, 9)
h2.Cells(h2row, 19) = h1.Cells(i + 2, 19)
h2.Cells(h2row, 20) = h1.Cells(i + 2, 20)
h2.Cells(h2row, 21) = h1.Cells(i + 3, 9)
h2.Cells(h2row, 22) = h1.Cells(i + 3, 19)
h2.Cells(h2row, 23) = h1.Cells(i + 3, 20)
h2.Cells(h2row, 24) = h1.Cells(i + 4, 9)
h2.Cells(h2row, 25) = h1.Cells(i + 4, 19)
h2.Cells(h2row, 26) = h1.Cells(i + 4, 20)
h2.Cells(h2row, 27) = h1.Cells(i + 5, 9)
h2.Cells(h2row, 28) = h1.Cells(i + 5, 19)
h2.Cells(h2row, 29) = h1.Cells(i + 5, 20)
h2.Cells(h2row, 30) = h1.Cells(i + 6, 9)
h2.Cells(h2row, 39) = Application.WorksheetFunction.Sum(h2.Cells(h2row, 13), (h2.Cells(h2row, 38)))
End If
End If
'Siete clientes
If h1.Cells(i, 2) = h1.Cells(i + 1, 2) And Left(h1.Cells(i, 6), 6) = "Planta" And _
(Left(h1.Cells(i + 1, 6), 3) = "Dis" Or Left(h1.Cells(i + 1, 6), 3) = "Bod" Or Left(h1.Cells(i + 1, 6), 3) = "Tek") _
And (Left(h1.Cells(i + 2, 6), 3) = "Dis" Or Left(h1.Cells(i + 2, 6), 3) = "Bod" Or Left(h1.Cells(i + 2, 6), 3) = "Tek") _
And (Left(h1.Cells(i + 3, 6), 3) = "Dis" Or Left(h1.Cells(i + 3, 6), 3) = "Bod" Or Left(h1.Cells(i + 3, 6), 3) = "Tek") _
And (Left(h1.Cells(i + 4, 6), 3) = "Dis" Or Left(h1.Cells(i + 4, 6), 3) = "Bod" Or Left(h1.Cells(i + 4, 6), 3) = "Tek") _
And (Left(h1.Cells(i + 5, 6), 3) = "Dis" Or Left(h1.Cells(i + 5, 6), 3) = "Bod" Or Left(h1.Cells(i + 5, 6), 3) = "Tek") _
And (Left(h1.Cells(i + 6, 6), 3) = "Dis" Or Left(h1.Cells(i + 6, 6), 3) = "Bod" Or Left(h1.Cells(i + 6, 6), 3) = "Tek") _
And (Left(h1.Cells(i + 7, 6), 3) = "Dis" Or Left(h1.Cells(i + 7, 6), 3) = "Bod" Or Left(h1.Cells(i + 7, 6), 3) = "Tek") _
And Left(h1.Cells(i + 8, 6), 6) = "Planta" Then
h2.Cells(h2row, 1) = h1.Cells(i, 1)
h2.Cells(h2row, 2) = h1.Cells(i, 2)
h2.Cells(h2row, 3) = h1.Cells(i, 6)
h2.Cells(h2row, 4) = h1.Cells(i + 1, 6)
h2.Cells(h2row, 5) = h1.Cells(i + 2, 6)
h2.Cells(h2row, 6) = h1.Cells(i + 3, 6)
h2.Cells(h2row, 7) = h1.Cells(i + 4, 6)
h2.Cells(h2row, 8) = h1.Cells(i + 5, 6)
h2.Cells(h2row, 9) = h1.Cells(i + 6, 6)
h2.Cells(h2row, 10) = h1.Cells(i + 7, 6)
If h2.Cells(h2row, 10) <> "" Then
h2.Cells(h2row, 13) = h1.Cells(i, 19)
h2.Cells(h2row, 14) = h1.Cells(i, 20)
h2.Cells(h2row, 15) = h1.Cells(i + 1, 9)
h2.Cells(h2row, 16) = h1.Cells(i + 1, 19)
h2.Cells(h2row, 17) = h1.Cells(i + 1, 20)
h2.Cells(h2row, 18) = h1.Cells(i + 2, 9)
h2.Cells(h2row, 19) = h1.Cells(i + 2, 19)
h2.Cells(h2row, 20) = h1.Cells(i + 2, 20)
h2.Cells(h2row, 21) = h1.Cells(i + 3, 9)
h2.Cells(h2row, 22) = h1.Cells(i + 3, 19)
h2.Cells(h2row, 23) = h1.Cells(i + 3, 20)
h2.Cells(h2row, 24) = h1.Cells(i + 4, 9)
h2.Cells(h2row, 25) = h1.Cells(i + 4, 19)
h2.Cells(h2row, 26) = h1.Cells(i + 4, 20)
h2.Cells(h2row, 27) = h1.Cells(i + 5, 9)
h2.Cells(h2row, 28) = h1.Cells(i + 5, 19)
h2.Cells(h2row, 29) = h1.Cells(i + 5, 20)
h2.Cells(h2row, 30) = h1.Cells(i + 6, 9)
h2.Cells(h2row, 31) = h1.Cells(i + 6, 19)
h2.Cells(h2row, 32) = h1.Cells(i + 6, 20)
h2.Cells(h2row, 33) = h1.Cells(i + 7, 9)
h2.Cells(h2row, 39) = Application.WorksheetFunction.Sum(h2.Cells(h2row, 13), (h2.Cells(h2row, 38)))
End If
End If
'Ocho clientes
If h1.Cells(i, 2) = h1.Cells(i + 1, 2) And Left(h1.Cells(i, 6), 6) = "Planta" And _
(Left(h1.Cells(i + 1, 6), 3) = "Dis" Or Left(h1.Cells(i + 1, 6), 3) = "Bod" Or Left(h1.Cells(i + 1, 6), 3) = "Tek") _
And (Left(h1.Cells(i + 2, 6), 3) = "Dis" Or Left(h1.Cells(i + 2, 6), 3) = "Bod" Or Left(h1.Cells(i + 2, 6), 3) = "Tek") _
And (Left(h1.Cells(i + 3, 6), 3) = "Dis" Or Left(h1.Cells(i + 3, 6), 3) = "Bod" Or Left(h1.Cells(i + 3, 6), 3) = "Tek") _
And (Left(h1.Cells(i + 4, 6), 3) = "Dis" Or Left(h1.Cells(i + 4, 6), 3) = "Bod" Or Left(h1.Cells(i + 4, 6), 3) = "Tek") _
And (Left(h1.Cells(i + 5, 6), 3) = "Dis" Or Left(h1.Cells(i + 5, 6), 3) = "Bod" Or Left(h1.Cells(i + 5, 6), 3) = "Tek") _
And (Left(h1.Cells(i + 6, 6), 3) = "Dis" Or Left(h1.Cells(i + 6, 6), 3) = "Bod" Or Left(h1.Cells(i + 6, 6), 3) = "Tek") _
And (Left(h1.Cells(i + 7, 6), 3) = "Dis" Or Left(h1.Cells(i + 7, 6), 3) = "Bod" Or Left(h1.Cells(i + 7, 6), 3) = "Tek") _
And (Left(h1.Cells(i + 8, 6), 3) = "Dis" Or Left(h1.Cells(i + 8, 6), 3) = "Bod" Or Left(h1.Cells(i + 8, 6), 3) = "Tek") _
And Left(h1.Cells(i + 9, 6), 6) = "Planta" Then
h2.Cells(h2row, 1) = h1.Cells(i, 1)
h2.Cells(h2row, 2) = h1.Cells(i, 2)
h2.Cells(h2row, 3) = h1.Cells(i, 6)
h2.Cells(h2row, 4) = h1.Cells(i + 1, 6)
h2.Cells(h2row, 5) = h1.Cells(i + 2, 6)
h2.Cells(h2row, 6) = h1.Cells(i + 3, 6)
h2.Cells(h2row, 7) = h1.Cells(i + 4, 6)
h2.Cells(h2row, 8) = h1.Cells(i + 5, 6)
h2.Cells(h2row, 9) = h1.Cells(i + 6, 6)
h2.Cells(h2row, 10) = h1.Cells(i + 7, 6)
h2.Cells(h2row, 11) = h1.Cells(i + 8, 6)
If h2.Cells(h2row, 11) <> "" Then
h2.Cells(h2row, 13) = h1.Cells(i, 19)
h2.Cells(h2row, 14) = h1.Cells(i, 20)
h2.Cells(h2row, 15) = h1.Cells(i + 1, 9)
h2.Cells(h2row, 16) = h1.Cells(i + 1, 19)
h2.Cells(h2row, 17) = h1.Cells(i + 1, 20)
h2.Cells(h2row, 18) = h1.Cells(i + 2, 9)
h2.Cells(h2row, 19) = h1.Cells(i + 2, 19)
h2.Cells(h2row, 20) = h1.Cells(i + 2, 20)
h2.Cells(h2row, 21) = h1.Cells(i + 3, 9)
h2.Cells(h2row, 22) = h1.Cells(i + 3, 19)
h2.Cells(h2row, 23) = h1.Cells(i + 3, 20)
h2.Cells(h2row, 24) = h1.Cells(i + 4, 9)
h2.Cells(h2row, 25) = h1.Cells(i + 4, 19)
h2.Cells(h2row, 26) = h1.Cells(i + 4, 20)
h2.Cells(h2row, 27) = h1.Cells(i + 5, 9)
h2.Cells(h2row, 28) = h1.Cells(i + 5, 19)
h2.Cells(h2row, 29) = h1.Cells(i + 5, 20)
h2.Cells(h2row, 30) = h1.Cells(i + 6, 9)
h2.Cells(h2row, 31) = h1.Cells(i + 6, 19)
h2.Cells(h2row, 32) = h1.Cells(i + 6, 20)
h2.Cells(h2row, 33) = h1.Cells(i + 7, 9)
h2.Cells(h2row, 34) = h1.Cells(i + 7, 19)
h2.Cells(h2row, 35) = h1.Cells(i + 7, 20)
h2.Cells(h2row, 36) = h1.Cells(i + 8, 9)
h2.Cells(h2row, 39) = Application.WorksheetFunction.Sum(h2.Cells(h2row, 13), (h2.Cells(h2row, 38)))
End If
End If
'Nueve clientes
If h1.Cells(i, 2) = h1.Cells(i + 1, 2) And Left(h1.Cells(i, 6), 6) = "Planta" And _
(Left(h1.Cells(i + 1, 6), 3) = "Dis" Or Left(h1.Cells(i + 1, 6), 3) = "Bod" Or Left(h1.Cells(i + 1, 6), 3) = "Tek") _
And (Left(h1.Cells(i + 2, 6), 3) = "Dis" Or Left(h1.Cells(i + 2, 6), 3) = "Bod" Or Left(h1.Cells(i + 2, 6), 3) = "Tek") _
And (Left(h1.Cells(i + 3, 6), 3) = "Dis" Or Left(h1.Cells(i + 3, 6), 3) = "Bod" Or Left(h1.Cells(i + 3, 6), 3) = "Tek") _
And (Left(h1.Cells(i + 4, 6), 3) = "Dis" Or Left(h1.Cells(i + 4, 6), 3) = "Bod" Or Left(h1.Cells(i + 4, 6), 3) = "Tek") _
And (Left(h1.Cells(i + 5, 6), 3) = "Dis" Or Left(h1.Cells(i + 5, 6), 3) = "Bod" Or Left(h1.Cells(i + 5, 6), 3) = "Tek") _
And (Left(h1.Cells(i + 6, 6), 3) = "Dis" Or Left(h1.Cells(i + 6, 6), 3) = "Bod" Or Left(h1.Cells(i + 6, 6), 3) = "Tek") _
And (Left(h1.Cells(i + 7, 6), 3) = "Dis" Or Left(h1.Cells(i + 7, 6), 3) = "Bod" Or Left(h1.Cells(i + 7, 6), 3) = "Tek") _
And (Left(h1.Cells(i + 8, 6), 3) = "Dis" Or Left(h1.Cells(i + 8, 6), 3) = "Bod" Or Left(h1.Cells(i + 8, 6), 3) = "Tek") _
And Left(h1.Cells(i + 9, 6), 6) = "Planta" Then
h2.Cells(h2row, 1) = h1.Cells(i, 1)
h2.Cells(h2row, 2) = h1.Cells(i, 2)
h2.Cells(h2row, 3) = h1.Cells(i, 6)
h2.Cells(h2row, 4) = h1.Cells(i + 1, 6)
h2.Cells(h2row, 5) = h1.Cells(i + 2, 6)
h2.Cells(h2row, 6) = h1.Cells(i + 3, 6)
h2.Cells(h2row, 7) = h1.Cells(i + 4, 6)
h2.Cells(h2row, 8) = h1.Cells(i + 5, 6)
h2.Cells(h2row, 9) = h1.Cells(i + 6, 6)
h2.Cells(h2row, 10) = h1.Cells(i + 7, 6)
h2.Cells(h2row, 11) = h1.Cells(i + 8, 6)
h2.Cells(h2row, 12) = h1.Cells(i + 9, 6)
If h2.Cells(h2row, 12) <> "" Then
h2.Cells(h2row, 13) = h1.Cells(i, 19)
h2.Cells(h2row, 14) = h1.Cells(i, 20)
h2.Cells(h2row, 15) = h1.Cells(i + 1, 9)
h2.Cells(h2row, 16) = h1.Cells(i + 1, 19)
h2.Cells(h2row, 17) = h1.Cells(i + 1, 20)
h2.Cells(h2row, 18) = h1.Cells(i + 2, 9)
h2.Cells(h2row, 19) = h1.Cells(i + 2, 19)
h2.Cells(h2row, 20) = h1.Cells(i + 2, 20)
h2.Cells(h2row, 21) = h1.Cells(i + 3, 9)
h2.Cells(h2row, 22) = h1.Cells(i + 3, 19)
h2.Cells(h2row, 23) = h1.Cells(i + 3, 20)
h2.Cells(h2row, 24) = h1.Cells(i + 4, 9)
h2.Cells(h2row, 25) = h1.Cells(i + 4, 19)
h2.Cells(h2row, 26) = h1.Cells(i + 4, 20)
h2.Cells(h2row, 27) = h1.Cells(i + 5, 9)
h2.Cells(h2row, 28) = h1.Cells(i + 5, 19)
h2.Cells(h2row, 29) = h1.Cells(i + 5, 20)
h2.Cells(h2row, 30) = h1.Cells(i + 6, 9)
h2.Cells(h2row, 31) = h1.Cells(i + 6, 19)
h2.Cells(h2row, 32) = h1.Cells(i + 6, 20)
h2.Cells(h2row, 33) = h1.Cells(i + 7, 9)
h2.Cells(h2row, 34) = h1.Cells(i + 7, 19)
h2.Cells(h2row, 35) = h1.Cells(i + 7, 20)
h2.Cells(h2row, 36) = h1.Cells(i + 8, 9)
h2.Cells(h2row, 37) = h1.Cells(i + 8, 19)
h2.Cells(h2row, 38) = h1.Cells(i + 8, 20)
h2.Cells(h2row, 39) = Application.WorksheetFunction.Sum(h2.Cells(h2row, 13), (h2.Cells(h2row, 38)))
End If
End If
Next i
End Sub

Dos detalles: si cuando se cumple un cliente ya no es necesario controlar el resto debes salir al Next... Sin evaluar el resto.

Y antes del bucle For pasar el cálculo a modo manual y al finalizar volverlo a automático para que calcule las fórmulas agregadas.

Sdos!

¿Cómo anduvo?

Si aún te queda algo lento enviámelo para probarlo.

Sdos!

Añade tu respuesta

Haz clic para o

Más respuestas relacionadas