Excel - Optimizacion de codigo

 
Vista:

Optimizacion de codigo

Publicado por perla Marina (2 intervenciones) el 28/07/2018 00:04:53
Hola, que Tal

Soy nueva en vba queria ver si podrian porfavor echandome la mano revisando si esta parte de codigo es optimo porque desde que lo agregue mi grafica tarda 2 minutos en crearse.

gracias de antemano.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
With objXLBook1.ActiveChart.SeriesCollection(1)
 
    .HasDataLabels = True
    Dim MiMatriz As Variant
    Dim TempDay As Integer
    MiMatriz = objXLBook1.Worksheets("Report").Range("D2:D" & xlLastRow)
    TempDay = objXLBook1.Worksheets("Report").Range("D2:D2")
 
    Dim i as Integer
    Dim cont as Integer
    i=1
    cont= xlLastRow - 1
 
    For i = 1 To xlLastRow - 1
 
        With objXLBook1.ActiveChart.SeriesCollection(1).Points(i)
 
            If TempDay <> MiMatriz(i, 1) Then
 
 
                .HasDataLabel = True
                .DataLabel.Text = MiMatriz(i, 1)
                .DataLabel.Position = xlLabelPositionBelow
                .DataLabel.Orientation = 60
 
            Else
                .HasDataLabel = True
                .DataLabel.Text = ""
            End If
        End With
 
        TempDay = MiMatriz(i, 1)
        Next i
End With
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder
Imágen de perfil de Antoni Masana
Val: 4.908
Oro
Ha mantenido su posición en Excel (en relación al último mes)
Gráfica de Excel

Optimizacion de codigo

Publicado por Antoni Masana (2477 intervenciones) el 28/07/2018 12:30:07
Veo una incoherencia.
En ti ejemplo hay dos WITH y los dos hacen referencia al mismo objeto y ademas uno dentro del otro. (Líneas 1 y 16). Y quita la variables del NEXT, hace más lento el proceso

Prueba esto
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
With objXLBook1.ActiveChart.SeriesCollection(1)
    .HasDataLabels = True
    Dim MiMatriz As Variant
    Dim TempDay As Integer
    MiMatriz = objXLBook1.Worksheets("Report").Range("D2:D" & xlLastRow)
    TempDay = objXLBook1.Worksheets("Report").Range("D2:D2")
 
    Dim i as Integer
    Dim cont as Integer
    i=1
    cont= xlLastRow - 1
    For i = 1 To xlLastRow - 1
        With .Points(i)
            If TempDay <> MiMatriz(i, 1) Then
                .HasDataLabel = True
                .DataLabel.Text = MiMatriz(i, 1)
                .DataLabel.Position = xlLabelPositionBelow
                .DataLabel.Orientation = 60
            Else
                .HasDataLabel = True
                .DataLabel.Text = ""
            End If
        End With
        TempDay = MiMatriz(i, 1)
        Next
End With

Ya dirás si mejora con estos cambios.

Saludos.
\\//_
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar