Grafica en excel y vba
Hola buenas tardes, quisiera que me ayudaran, tengo una macro qque realiza una grafica(simetrica) en la macro tiene un maximo y un minimo(esto es para rotular la grafica) lo que quiero es que cada vez que introduzca un valor diferentre a las celdas que estan asociadas a dicha grafica, la grafica se refreseque y me respete los minimos y los maximos.
pongo mi subrutina:
Sub Grafica_2()
'
ng = Cells(3, 12)
Range("Q1:R6" + CStr(ng)).Select
Cells(11, 1).Select
ActiveSheet.Shapes.AddChart.Select
ActiveChart.ChartType = xlBarStacked
ActiveChart.SetSourceData Source:=Range("Hoja1!$H$3:$H$7,Hoja1!$R$1:$R$6" + CStr(ng))
ActiveChart.ChartType = xlBarStacked
ActiveChart.Axes(xlValue).Select
ActiveChart.Axes(xlValue).MinimumScale = Cells(1, 20)
ActiveChart.Axes(xlValue).MaximumScale = Cells(2, 20)
Selection.MinorTickMark = xlCross
ActiveChart.Axes(xlValue).CrossesAt = 100
ActiveChart.Legend.Select
Selection.Delete
Range("L9").Select
Worksheets(1).ChartObjects(1).Select
ActiveChart.SeriesCollection(1).Select
ActiveSheet.ChartObjects(1).Activate
ActiveSheet.ChartObjects(1).Activate
ActiveChart.SeriesCollection(1).Interior.Color = RGB(255, 255, 255)
ActiveChart.Axes(xlCategory).Select
ActiveSheet.ChartObjects(1).Activate
ActiveChart.Axes(xlCategory).Select
Selection.TickLabelPosition = xlHigh
ActiveSheet.ChartObjects(1).Activate
ActiveChart.PlotArea.Select
ActiveChart.SeriesCollection(1).XValues = "='Hoja1'!$A$2:$A$8"
ActiveSheet.ChartObjects(1).Activate
ActiveChart.Axes(xlValue).MajorGridlines.Select
ActiveChart.Axes(xlValue).MajorGridlines.Border.Color = RGB(255, 255, 255)
Range("A1").Select
End Sub
Sub Grafica_2()'' Grafica Macro'' Acceso directo: CTRL+l' ng = Cells(3, 12) Range("Q1:R6" + CStr(ng)).Select Cells(11, 1).Select ActiveSheet.Shapes.AddChart.Select ActiveChart.ChartType = xlBarStacked ActiveChart.SetSourceData Source:=Range("Hoja1!$H$3:$H$7,Hoja1!$R$1:$R$6" + CStr(ng)) ActiveChart.ChartType = xlBarStacked ActiveChart.Axes(xlValue).Select ActiveChart.Axes(xlValue).MinimumScale = Cells(1, 20) ActiveChart.Axes(xlValue).MaximumScale = Cells(2, 20) Selection.MinorTickMark = xlCross ActiveChart.Axes(xlValue).CrossesAt = 100 ActiveChart.Legend.Select Selection.Delete Range("L9").Select Worksheets(1).ChartObjects(1).Select ActiveChart.SeriesCollection(1).Select ActiveSheet.ChartObjects(1).Activate ActiveSheet.ChartObjects(1).Activate ActiveChart.SeriesCollection(1).Interior.Color = RGB(255, 255, 255) ActiveChart.Axes(xlCategory).Select ActiveSheet.ChartObjects(1).Activate ActiveChart.Axes(xlCategory).Select Selection.TickLabelPosition = xlHigh ActiveSheet.ChartObjects(1).Activate ActiveChart.PlotArea.Select ActiveChart.SeriesCollection(1).XValues = "='Hoja1'!$A$2:$A$8" ActiveSheet.ChartObjects(1).Activate ActiveChart.Axes(xlValue).MajorGridlines.Select ActiveChart.Axes(xlValue).MajorGridlines.Border.Color = RGB(255, 255, 255) Range("A1").Select
End Sub
como le hago?
y tambien como puedo centrar mi grafica o ponerla en un area que yo quiero. Saludos!
pongo mi subrutina:
Sub Grafica_2()
'
ng = Cells(3, 12)
Range("Q1:R6" + CStr(ng)).Select
Cells(11, 1).Select
ActiveSheet.Shapes.AddChart.Select
ActiveChart.ChartType = xlBarStacked
ActiveChart.SetSourceData Source:=Range("Hoja1!$H$3:$H$7,Hoja1!$R$1:$R$6" + CStr(ng))
ActiveChart.ChartType = xlBarStacked
ActiveChart.Axes(xlValue).Select
ActiveChart.Axes(xlValue).MinimumScale = Cells(1, 20)
ActiveChart.Axes(xlValue).MaximumScale = Cells(2, 20)
Selection.MinorTickMark = xlCross
ActiveChart.Axes(xlValue).CrossesAt = 100
ActiveChart.Legend.Select
Selection.Delete
Range("L9").Select
Worksheets(1).ChartObjects(1).Select
ActiveChart.SeriesCollection(1).Select
ActiveSheet.ChartObjects(1).Activate
ActiveSheet.ChartObjects(1).Activate
ActiveChart.SeriesCollection(1).Interior.Color = RGB(255, 255, 255)
ActiveChart.Axes(xlCategory).Select
ActiveSheet.ChartObjects(1).Activate
ActiveChart.Axes(xlCategory).Select
Selection.TickLabelPosition = xlHigh
ActiveSheet.ChartObjects(1).Activate
ActiveChart.PlotArea.Select
ActiveChart.SeriesCollection(1).XValues = "='Hoja1'!$A$2:$A$8"
ActiveSheet.ChartObjects(1).Activate
ActiveChart.Axes(xlValue).MajorGridlines.Select
ActiveChart.Axes(xlValue).MajorGridlines.Border.Color = RGB(255, 255, 255)
Range("A1").Select
End Sub
Sub Grafica_2()'' Grafica Macro'' Acceso directo: CTRL+l' ng = Cells(3, 12) Range("Q1:R6" + CStr(ng)).Select Cells(11, 1).Select ActiveSheet.Shapes.AddChart.Select ActiveChart.ChartType = xlBarStacked ActiveChart.SetSourceData Source:=Range("Hoja1!$H$3:$H$7,Hoja1!$R$1:$R$6" + CStr(ng)) ActiveChart.ChartType = xlBarStacked ActiveChart.Axes(xlValue).Select ActiveChart.Axes(xlValue).MinimumScale = Cells(1, 20) ActiveChart.Axes(xlValue).MaximumScale = Cells(2, 20) Selection.MinorTickMark = xlCross ActiveChart.Axes(xlValue).CrossesAt = 100 ActiveChart.Legend.Select Selection.Delete Range("L9").Select Worksheets(1).ChartObjects(1).Select ActiveChart.SeriesCollection(1).Select ActiveSheet.ChartObjects(1).Activate ActiveSheet.ChartObjects(1).Activate ActiveChart.SeriesCollection(1).Interior.Color = RGB(255, 255, 255) ActiveChart.Axes(xlCategory).Select ActiveSheet.ChartObjects(1).Activate ActiveChart.Axes(xlCategory).Select Selection.TickLabelPosition = xlHigh ActiveSheet.ChartObjects(1).Activate ActiveChart.PlotArea.Select ActiveChart.SeriesCollection(1).XValues = "='Hoja1'!$A$2:$A$8" ActiveSheet.ChartObjects(1).Activate ActiveChart.Axes(xlValue).MajorGridlines.Select ActiveChart.Axes(xlValue).MajorGridlines.Border.Color = RGB(255, 255, 255) Range("A1").Select
End Sub
como le hago?
y tambien como puedo centrar mi grafica o ponerla en un area que yo quiero. Saludos!
1 Respuesta
Respuesta de prozac
1