Crear Macro en excel para generar varias gráficas en una hoja
publicado
Buenas tardes me pueden colaborar con este problemita que tengo:
Tengo que realizar 440 graficos o mas en excel de una tabla.
La macro que tengo los realiza pero en diferentes hojas del libro pero me solicitaron que mejor sea en varias hojas pero en cada hoja esten 50 graficos en dos columnas
la macro que tengo es:
[COLOR=#333333][FONT=arial]Sub principal()[/FONT][/COLOR]
[COLOR=#333333][FONT=arial]Dim fila As Integer[/FONT][/COLOR]
[COLOR=#333333][FONT=arial]Dim Rango As String, Rango1 As String[/FONT][/COLOR]
[COLOR=#333333][FONT=arial]Range("A3:A3").Select[/FONT][/COLOR]
[COLOR=#333333][FONT=arial]Selection.End(xlDown).Select ' Ubico el último registro de la columna[/FONT][/COLOR]
[COLOR=#333333][FONT=arial]Dim b As String[/FONT][/COLOR]
[COLOR=#333333][FONT=arial]b = ActiveWindow.RangeSelection.Row ' Declaro la fí*la como una variable[/FONT][/COLOR]
[COLOR=#333333][FONT=arial]Dim Mensaje, Estilo, Tí*tulo, Respuesta, MiCadena[/FONT][/COLOR]
[COLOR=#333333][FONT=arial]Mensaje = "La cantidad de graficos a crear es de: " & b ' Define el mensaje.[/FONT][/COLOR]
[COLOR=#333333][FONT=arial]Estilo = vbOKOnly + vbInformation + vbDefaultButton2 ' Define los botones.[/FONT][/COLOR]
[COLOR=#333333][FONT=arial]Tí*tulo = "Fila" ' Define el tí*tulo.[/FONT][/COLOR]
[COLOR=#333333][FONT=arial]Respuesta = MsgBox(Mensaje, Estilo, Tí*tulo)[/FONT][/COLOR]
[COLOR=#333333][FONT=arial]fila = 2[/FONT][/COLOR]
[COLOR=#333333][FONT=arial]Do[/FONT][/COLOR]
[COLOR=#333333][FONT=arial]' Grafica No 1[/FONT][/COLOR]
[COLOR=#333333][FONT=arial]Worksheets("Hoja5").Rows(1).Copy[/FONT][/COLOR]
[COLOR=#333333][FONT=arial]Sheets.Add After:=Sheets(Sheets.Count)[/FONT][/COLOR]
[COLOR=#333333][FONT=arial]Rows("1").Select[/FONT][/COLOR]
[COLOR=#333333][FONT=arial]ActiveSheet.Paste[/FONT][/COLOR]
[COLOR=#333333][FONT=arial]xxx = ActiveCell.Worksheet.Name[/FONT][/COLOR]
[COLOR=#333333][FONT=arial]Worksheets("Hoja5").Rows(fila).Copy[/FONT][/COLOR]
[COLOR=#333333][FONT=arial]Worksheets(xxx).Select[/FONT][/COLOR]
[COLOR=#333333][FONT=arial]Rows(2).Select[/FONT][/COLOR]
[COLOR=#333333][FONT=arial]Selection.PasteSpecial Paste:=xlValues[/FONT][/COLOR]
[COLOR=#333333][FONT=arial]Worksheets(xxx).Select[/FONT][/COLOR]
[COLOR=#333333][FONT=arial]Range("C1:J2").Select[/FONT][/COLOR]
[COLOR=#333333][FONT=arial]ActiveSheet.Shapes.AddChart.Select[/FONT][/COLOR]
[COLOR=#333333][FONT=arial]ActiveChart.ChartType = xlColumnClustered[/FONT][/COLOR]
[COLOR=#333333][FONT=arial]n = Len(xxx)[/FONT][/COLOR]
[COLOR=#333333][FONT=arial]x = Mid(ActiveChart.Name, n + 2, 20)[/FONT][/COLOR]
[COLOR=#333333][FONT=arial]ActiveSheet.Shapes(x).IncrementLeft -260.5[/FONT][/COLOR]
[COLOR=#333333][FONT=arial]ActiveSheet.Shapes(x).IncrementTop 15.95[/FONT][/COLOR]
[COLOR=#333333][FONT=arial]ActiveSheet.Shapes(x).ScaleWidth 1.25, msoFalse, msoScaleFromTopLeft[/FONT][/COLOR]
[COLOR=#333333][FONT=arial]ActiveSheet.Shapes(x).ScaleHeight 1.25, msoFalse, msoScaleFromTopLeft[/FONT][/COLOR]
[COLOR=#333333][FONT=arial]'Cambiamos el título del gráfico[/FONT][/COLOR]
[COLOR=#333333][FONT=arial]ActiveChart.ChartArea.Select[/FONT][/COLOR]
[COLOR=#333333][FONT=arial]Selection.AutoScaleFont = True[/FONT][/COLOR]
[COLOR=#333333][FONT=arial]With Selection.Font[/FONT][/COLOR]
[COLOR=#333333][FONT=arial].Name = "Arial"[/FONT][/COLOR]
[COLOR=#333333][FONT=arial].Size = 10[/FONT][/COLOR]
[COLOR=#333333][FONT=arial].Strikethrough = False[/FONT][/COLOR]
[COLOR=#333333][FONT=arial].Superscript = False[/FONT][/COLOR]
[COLOR=#333333][FONT=arial].Subscript = False[/FONT][/COLOR]
[COLOR=#333333][FONT=arial].OutlineFont = False[/FONT][/COLOR]
[COLOR=#333333][FONT=arial].Shadow = False[/FONT][/COLOR]
[COLOR=#333333][FONT=arial].Underline = xlUnderlineStyleNone[/FONT][/COLOR]
[COLOR=#333333][FONT=arial].ColorIndex = xlAutomatic[/FONT][/COLOR]
[COLOR=#333333][FONT=arial].Background = xlAutomatic[/FONT][/COLOR]
[COLOR=#333333][FONT=arial]End With[/FONT][/COLOR]
[COLOR=#333333][FONT=arial]With ActiveChart[/FONT][/COLOR]
[COLOR=#333333][FONT=arial].HasTitle = True[/FONT][/COLOR]
[COLOR=#333333][FONT=arial].Axes(xlCategory, xlPrimary).HasTitle = False[/FONT][/COLOR]
[COLOR=#333333][FONT=arial].Axes(xlValue, xlPrimary).HasTitle = False[/FONT][/COLOR]
[COLOR=#333333][FONT=arial]End With[/FONT][/COLOR]
[COLOR=#333333][FONT=arial]'Quitamos la leyenda[/FONT][/COLOR]
[COLOR=#333333][FONT=arial]ActiveChart.HasLegend = False[/FONT][/COLOR]
[COLOR=#333333][FONT=arial]'Ponemos tamaño 7 para el eje Y[/FONT][/COLOR]
[COLOR=#333333][FONT=arial]ActiveChart.Axes(xlValue).Select[/FONT][/COLOR]
[COLOR=#333333][FONT=arial]Selection.TickLabels.AutoScaleFont = True[/FONT][/COLOR]
[COLOR=#333333][FONT=arial]With Selection.TickLabels.Font[/FONT][/COLOR]
[COLOR=#333333][FONT=arial].Size = 7[/FONT][/COLOR]
[COLOR=#333333][FONT=arial].Name = "Arial"[/FONT][/COLOR]
[COLOR=#333333][FONT=arial]End With[/FONT][/COLOR]
[COLOR=#333333][FONT=arial]'Ponemos tamaño 7 para el eje X[/FONT][/COLOR]
[COLOR=#333333][FONT=arial]ActiveChart.Axes(xlCategory).Select[/FONT][/COLOR]
[COLOR=#333333][FONT=arial]Selection.TickLabels.AutoScaleFont = True[/FONT][/COLOR]
[COLOR=#333333][FONT=arial]With Selection.TickLabels.Font[/FONT][/COLOR]
[COLOR=#333333][FONT=arial].Size = 7[/FONT][/COLOR]
[COLOR=#333333][FONT=arial].Name = "Arial"[/FONT][/COLOR]
[COLOR=#333333][FONT=arial]End With[/FONT][/COLOR]
[COLOR=#333333][FONT=arial]'Ponemos el título en negrita[/FONT][/COLOR]
[COLOR=#333333][FONT=arial]ActiveChart.ChartTitle.Select[/FONT][/COLOR]
[COLOR=#333333][FONT=arial]Selection.Font.Bold = True[/FONT][/COLOR]
[COLOR=#333333][FONT=arial]fila = fila + 1[/FONT][/COLOR]
[COLOR=#333333][FONT=arial]Loop Until fila > 3[/FONT][/COLOR]
[COLOR=#333333][FONT=arial]End Sub
Buenas tardes me pueden colaborar con este problemita que tengo:
Tengo que realizar 440 graficos o mas en excel de una tabla.
La macro que tengo los realiza pero en diferentes hojas del libro pero me solicitaron que mejor sea en varias hojas pero en cada hoja esten 50 graficos en dos columnas
la macro que tengo es:
[/font][/color]
Tabla y Ejemplo de Grafico para foro.rar