Drama con gráficos y macros
HOLA
Soy un nuevo usuario y me da mucho gusto pertenecer a esta comunidad ...
Mi consulta es la siguiente :
Tengo una poequeña hoja que tiene dos campos, estos son "nombre" y "edad", el titulo "nombre" esta en la celda A1 y el titulo "edad" esta en la B1, actualmente a esta mini-base le agregue 6 registros, cree una macro que selecciona los registros y crea un gráfico, para esto utilice ña función :
range(selection,selection.end(xldown)).select
*** esto es para que me selecxcione todos los registros actuales ... Osea .. Si tengo 20 registros, la macro deberia crearme un grafico con 20 retgistros ....
si tengo 5 registros... La macro debería crearme un gráfico con 5 registros ...
Lamentablemente al crear la macro, la selección de rangos funciona muy bien, pero en los pasos donde se creo el gráfico asume el rango que se utilizo al crear la macro
EJ : tenia 6 registros al principio .. Y me tomo desde el rango A1 hasta el B7
en la linea *** ActiveChart.SetSourceData Source:=Sheets("datos").Range("A1:B7"), PlotBy:= _
xlColumns ***
la sentencia Range("A1:B7") me toma fijo este rango... Y me gustaria que tomara los rangos segun los registros que tenga
por ejemplo, si tengo 10 registros deberia seleccionarlos de manera automatica y no siempre Range("A1:B7")
**********
aqui esta la macro
Range("A1").Select
Range(Selection, Selection.End(xlToRight)).Select
Range(Selection, Selection.End(xlDown)).Select
Charts.Add
ActiveChart.ChartType = xlColumnClustered
ActiveChart.SetSourceData Source:=Sheets("datos").Range("A1:B7"), PlotBy:= _
xlColumns
ActiveChart.Location Where:=xlLocationAsNewSheet, Name:="GRAFICO"
With ActiveChart
.HasTitle = True
.ChartTitle.Characters.Text = "EDADES"
.Axes(xlCategory, xlPrimary).HasTitle = False
.Axes(xlValue, xlPrimary).HasTitle = False
End With
ActiveChart.HasLegend = True
ActiveChart.Legend.Select
Selection.Position = xlBottom
ActiveChart.ApplyDataLabels Type:=xlDataLabelsShowValue, LegendKey:=False
ActiveChart.ChartArea.Select
Selection.AutoScaleFont = True
With Selection.Font
.Name = "Arial"
.Size = 24
.Strikethrough = False
.Superscript = False
.Subscript = False
.OutlineFont = False
.Shadow = False
.Underline = xlUnderlineStyleNone
.ColorIndex = xlAutomatic
.Background = xlAutomatic
End With
With Selection.Interior
.ColorIndex = 28
.Pattern = xlSolid
End With
Sheets("GRAFICO").Select
Sheets("GRAFICO").Move
ActiveWorkbook.SaveAs Filename:="C:\Mis documentos\GRAFICO.xls", FileFormat _
:=xlNormal, Password:="", WriteResPassword:="", ReadOnlyRecommended:= _
False, CreateBackup:=False
ActiveWorkbook.Close
Windows("MACRO1 DAVID LAVADO.xls").Activate
Range("C1").Select
MsgBox "TAREA FINALIZADA"
*****
Espero de corazón que me ayuden
Atentamente
ProfesorTcc
Soy un nuevo usuario y me da mucho gusto pertenecer a esta comunidad ...
Mi consulta es la siguiente :
Tengo una poequeña hoja que tiene dos campos, estos son "nombre" y "edad", el titulo "nombre" esta en la celda A1 y el titulo "edad" esta en la B1, actualmente a esta mini-base le agregue 6 registros, cree una macro que selecciona los registros y crea un gráfico, para esto utilice ña función :
range(selection,selection.end(xldown)).select
*** esto es para que me selecxcione todos los registros actuales ... Osea .. Si tengo 20 registros, la macro deberia crearme un grafico con 20 retgistros ....
si tengo 5 registros... La macro debería crearme un gráfico con 5 registros ...
Lamentablemente al crear la macro, la selección de rangos funciona muy bien, pero en los pasos donde se creo el gráfico asume el rango que se utilizo al crear la macro
EJ : tenia 6 registros al principio .. Y me tomo desde el rango A1 hasta el B7
en la linea *** ActiveChart.SetSourceData Source:=Sheets("datos").Range("A1:B7"), PlotBy:= _
xlColumns ***
la sentencia Range("A1:B7") me toma fijo este rango... Y me gustaria que tomara los rangos segun los registros que tenga
por ejemplo, si tengo 10 registros deberia seleccionarlos de manera automatica y no siempre Range("A1:B7")
**********
aqui esta la macro
Range("A1").Select
Range(Selection, Selection.End(xlToRight)).Select
Range(Selection, Selection.End(xlDown)).Select
Charts.Add
ActiveChart.ChartType = xlColumnClustered
ActiveChart.SetSourceData Source:=Sheets("datos").Range("A1:B7"), PlotBy:= _
xlColumns
ActiveChart.Location Where:=xlLocationAsNewSheet, Name:="GRAFICO"
With ActiveChart
.HasTitle = True
.ChartTitle.Characters.Text = "EDADES"
.Axes(xlCategory, xlPrimary).HasTitle = False
.Axes(xlValue, xlPrimary).HasTitle = False
End With
ActiveChart.HasLegend = True
ActiveChart.Legend.Select
Selection.Position = xlBottom
ActiveChart.ApplyDataLabels Type:=xlDataLabelsShowValue, LegendKey:=False
ActiveChart.ChartArea.Select
Selection.AutoScaleFont = True
With Selection.Font
.Name = "Arial"
.Size = 24
.Strikethrough = False
.Superscript = False
.Subscript = False
.OutlineFont = False
.Shadow = False
.Underline = xlUnderlineStyleNone
.ColorIndex = xlAutomatic
.Background = xlAutomatic
End With
With Selection.Interior
.ColorIndex = 28
.Pattern = xlSolid
End With
Sheets("GRAFICO").Select
Sheets("GRAFICO").Move
ActiveWorkbook.SaveAs Filename:="C:\Mis documentos\GRAFICO.xls", FileFormat _
:=xlNormal, Password:="", WriteResPassword:="", ReadOnlyRecommended:= _
False, CreateBackup:=False
ActiveWorkbook.Close
Windows("MACRO1 DAVID LAVADO.xls").Activate
Range("C1").Select
MsgBox "TAREA FINALIZADA"
*****
Espero de corazón que me ayuden
Atentamente
ProfesorTcc
1 respuesta
Respuesta de Elsa Matilde
1