Cambiar el orden de línea de tendencia de una gráfica usando VBA

Deladier

Board Regular
Joined
May 4, 2005
Messages
127
Hola.

Tengo una gráfica y mediante VBA puedo cambiar el Orden de la línea de tendencia de esa gráfica pero al tratar de cambiar de polinomial a lineal tengo problemas al parecer con el Orden. Según creo yo, 'Order' ya no debería aparecer para una gráfica lineal, pero no sé si ese sea el problema únicamente.
Aquí está mi codigo:

Sub Macro1()

Dim grado As Integer, tipo As String, sel As String


grado = Range("B10").Value

ActiveSheet.ChartObjects("Gráfico 1").Activate
ActiveChart.SeriesCollection(1).Trendlines(1).Select


If grado = 1 Then tipo = xlLinear
If grado > 1 Then tipo = xlPolynomial


With Selection
.Type = tipo
.Order = grado
.Forward = 0
.Backward = 0
.InterceptIsAuto = True
.DisplayEquation = True
.DisplayRSquared = True
.NameIsAuto = True
End With

End Sub


¿Cómo se puede solucionar ésto?

Gracias de antemano. Saludos
 

Excel Facts

Save Often
If you start asking yourself if now is a good time to save your Excel workbook, the answer is Yes
¿Como puedo hacer para que en el código '.Order = grado' aparezca (para una gráfica polinomial) o desaparezca (para una gráfica lineal)? Creo que eso solucionaría el problema.
 
Upvote 0
Deladier,

Que pasa si pones el "With Selection" statement para cada condicion?

Cuando se lineal no incluyas el .Order y cuando sea polinominal si.

Saludos,

Benjamin
 
Upvote 0
Intenta así,

Code:
With Selection
    .Type = tipo
    If .Type = xlPolynomial Then .Order = grado
    .Forward = 0
    .Backward = 0
    .InterceptIsAuto = True
    .DisplayEquation = True
    .DisplayRSquared = True
    .NameIsAuto = True
End With

Saludos
 
Upvote 0

Forum statistics

Threads
1,207,436
Messages
6,078,542
Members
446,345
Latest member
MicCh

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top