Saltar al contenido
View in the app

A better way to browse. Learn more.

Ayuda Excel

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

autoajustar gráfico en excel con VBA

publicado

Muy buenas tardes a todos, mi nombre es Gonzalo (LordAntrax) y deseo hacerles una consulta:

Estoy creando gráficos con VBA en Excel. El tema es que todo corre perfecto, pero al momento de autoajustar el tamaño del mismo, no me deja hacerlo. El código es el siguiente:

'-- le indico la última celda con datos

fin = Cells(Worksheets("Hoja4").Range("B" & Rows.Count).End(xlUp).Row, 1).Row

'--Código de contrucción de gráfico

rngtit = "A2:A" & fin '-- Rango de titulos

rngdat = "B1:B" & fin '-- Rango de Datos

'--Gráfico

Range("A6:B" & fila).Select

Charts.Add

ActiveChart.ChartType = xl3DPie

ActiveChart.SetSourceData Source:=Sheets("Hoja4").Range("A6:B" & fila), PlotBy:=xlColumns

ActiveChart.Location Where:=xlLocationAsObject, Name:="Hoja4"

'-- Acá supuestamente, guardo los valores para el minimumScale y MaximumScale

max = Application.WorksheetFunction.max(Range("B6:B" & fin))

min = Application.WorksheetFunction.min(Range("B6:B" & fin))

unit = WorksheetFunction.Average(Range("B6:B" & fin))

valores = Range("B6:B" & fin).CountLarge

'--como tengo 2 gráficos, recorro los activos para su autoajuste

For Each ChartObjects In ActiveSheet.ChartObjects

With ActiveChart.Axes(xlValue)

.MinimumScale = min * 0.95

.MaximumScale = max * 1.05

.MinorUnit = unit / valores

.MajorUnit = unit / valores

End With

Next

Al llegar a la sentencia .MinimumScale = Range("B6"), me da un error de que el objeto ya no es válido.

Alguien me podría dar una mano con esto? :suspicion:

Desde ya, muchas gracias.

Saludos a todos

Featured Replies

publicado

Hola,

por favor, prueba así:

 For Each [COLOR=#0000ff]ChartObjects[/COLOR] In ActiveSheet.ChartObjects
 With [COLOR=#ff0000]ChartObjects.Chart.[/COLOR]Axes(xlValue)
 .MinimumScale = min * 0.95
 .MaximumScale = max * 1.05
 .MinorUnit = unit / valores
 .MajorUnit = unit / valores
 End With
 Next

No me queda claro si estás tratando de ajustar el eje Y de un gráfico de tipo pie (lo digo porque veo que usas: ActiveChart.ChartType = xl3DPie). Si es así, no creo que tengas mucho éxito pues estos gráficos no tienen eje Y.

Archivado

Este tema está ahora archivado y está cerrado a más respuestas.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.