Quantcast
Channel: Excel Help Forum - Excel Programming / VBA / Macros
Viewing all articles
Browse latest Browse all 50079

Simplify 120 macros of the same kind

$
0
0
Please, I need help to simplify 120 blocks of text like this:

Code:

Sub RedimensionarGraficos001A()
    Columns("A:A").Select
    Application.CutCopyMode = False
    Charts.Add
    ActiveChart.ChartType = xlLineMarkers
    ActiveChart.SetSourceData Source:=Sheets("Plan1").Columns("A:A")
    ActiveChart.Location Where:=xlLocationAsObject, Name:="Plan1"
    ActiveSheet.Shapes("Gráfico 1").IncrementLeft -183.75
    ActiveSheet.Shapes("Gráfico 1").IncrementTop -105#
    ActiveSheet.Shapes("Gráfico 1").ScaleHeight 1.94, msoFalse, _
        msoScaleFromTopLeft
    ActiveSheet.Shapes("Gráfico 1").ScaleWidth 2.04, msoFalse, msoScaleFromTopLeft
End Sub
Sub RedimensionarGraficos002B()
    Columns("B:B").Select
    Application.CutCopyMode = False
    Charts.Add
    ActiveChart.ChartType = xlLineMarkers
    ActiveChart.SetSourceData Source:=Sheets("Plan1").Columns("B:B")
    ActiveChart.Location Where:=xlLocationAsObject, Name:="Plan1"
    ActiveSheet.Shapes("Gráfico 1").IncrementLeft -183.75
    ActiveSheet.Shapes("Gráfico 1").IncrementTop -105#
    ActiveSheet.Shapes("Gráfico 1").ScaleHeight 1.94, msoFalse, _
        msoScaleFromTopLeft
    ActiveSheet.Shapes("Gráfico 1").ScaleWidth 2.04, msoFalse, msoScaleFromTopLeft
End Sub
Sub RedimensionarGraficos003C()
    Columns("C:C").Select
    Application.CutCopyMode = False
    Charts.Add
    ActiveChart.ChartType = xlLineMarkers
    ActiveChart.SetSourceData Source:=Sheets("Plan1").Columns("C:C")
    ActiveChart.Location Where:=xlLocationAsObject, Name:="Plan1"
    ActiveSheet.Shapes("Gráfico 1").IncrementLeft -183.75
    ActiveSheet.Shapes("Gráfico 1").IncrementTop -105#
    ActiveSheet.Shapes("Gráfico 1").ScaleHeight 1.94, msoFalse, _
        msoScaleFromTopLeft
    ActiveSheet.Shapes("Gráfico 1").ScaleWidth 2.04, msoFalse, msoScaleFromTopLeft
End Sub
Sub RedimensionarGraficos004D()
    Columns("D:D").Select
    Application.CutCopyMode = False
    Charts.Add
    ActiveChart.ChartType = xlLineMarkers
    ActiveChart.SetSourceData Source:=Sheets("Plan1").Columns("D:D")
    ActiveChart.Location Where:=xlLocationAsObject, Name:="Plan1"
    ActiveSheet.Shapes("Gráfico 1").IncrementLeft -183.75
    ActiveSheet.Shapes("Gráfico 1").IncrementTop -105#
    ActiveSheet.Shapes("Gráfico 1").ScaleHeight 1.94, msoFalse, _
        msoScaleFromTopLeft
    ActiveSheet.Shapes("Gráfico 1").ScaleWidth 2.04, msoFalse, msoScaleFromTopLeft
End Sub
Sub RedimensionarGraficos005E()
    Columns("E:E").Select
    Application.CutCopyMode = False
    Charts.Add
    ActiveChart.ChartType = xlLineMarkers
    ActiveChart.SetSourceData Source:=Sheets("Plan1").Columns("E:E")
    ActiveChart.Location Where:=xlLocationAsObject, Name:="Plan1"
    ActiveSheet.Shapes("Gráfico 1").IncrementLeft -183.75
    ActiveSheet.Shapes("Gráfico 1").IncrementTop -105#
    ActiveSheet.Shapes("Gráfico 1").ScaleHeight 1.94, msoFalse, _
        msoScaleFromTopLeft
    ActiveSheet.Shapes("Gráfico 1").ScaleWidth 2.04, msoFalse, msoScaleFromTopLeft
End Sub
Sub RedimensionarGraficos006F()
    Columns("F:F").Select
    Application.CutCopyMode = False
    Charts.Add
    ActiveChart.ChartType = xlLineMarkers
    ActiveChart.SetSourceData Source:=Sheets("Plan1").Columns("F:F")
    ActiveChart.Location Where:=xlLocationAsObject, Name:="Plan1"
    ActiveSheet.Shapes("Gráfico 1").IncrementLeft -183.75
    ActiveSheet.Shapes("Gráfico 1").IncrementTop -105#
    ActiveSheet.Shapes("Gráfico 1").ScaleHeight 1.94, msoFalse, _
        msoScaleFromTopLeft
    ActiveSheet.Shapes("Gráfico 1").ScaleWidth 2.04, msoFalse, msoScaleFromTopLeft
End Sub
Sub RedimensionarGraficos007G()
    Columns("G:G").Select
    Application.CutCopyMode = False
    Charts.Add
    ActiveChart.ChartType = xlLineMarkers
    ActiveChart.SetSourceData Source:=Sheets("Plan1").Columns("G:G")
    ActiveChart.Location Where:=xlLocationAsObject, Name:="Plan1"
    ActiveSheet.Shapes("Gráfico 1").IncrementLeft -183.75
    ActiveSheet.Shapes("Gráfico 1").IncrementTop -105#
    ActiveSheet.Shapes("Gráfico 1").ScaleHeight 1.94, msoFalse, _
        msoScaleFromTopLeft
    ActiveSheet.Shapes("Gráfico 1").ScaleWidth 2.04, msoFalse, msoScaleFromTopLeft
End Sub
Sub RedimensionarGraficos008H()
    Columns("H:H").Select
    Application.CutCopyMode = False
    Charts.Add
    ActiveChart.ChartType = xlLineMarkers
    ActiveChart.SetSourceData Source:=Sheets("Plan1").Columns("H:H")
    ActiveChart.Location Where:=xlLocationAsObject, Name:="Plan1"
    ActiveSheet.Shapes("Gráfico 1").IncrementLeft -183.75
    ActiveSheet.Shapes("Gráfico 1").IncrementTop -105#
    ActiveSheet.Shapes("Gráfico 1").ScaleHeight 1.94, msoFalse, _
        msoScaleFromTopLeft
    ActiveSheet.Shapes("Gráfico 1").ScaleWidth 2.04, msoFalse, msoScaleFromTopLeft
End Sub
Sub RedimensionarGraficos009I()
    Columns("I:I").Select
    Application.CutCopyMode = False
    Charts.Add
    ActiveChart.ChartType = xlLineMarkers
    ActiveChart.SetSourceData Source:=Sheets("Plan1").Columns("I:I")
    ActiveChart.Location Where:=xlLocationAsObject, Name:="Plan1"
    ActiveSheet.Shapes("Gráfico 1").IncrementLeft -183.75
    ActiveSheet.Shapes("Gráfico 1").IncrementTop -105#
    ActiveSheet.Shapes("Gráfico 1").ScaleHeight 1.94, msoFalse, _
        msoScaleFromTopLeft
    ActiveSheet.Shapes("Gráfico 1").ScaleWidth 2.04, msoFalse, msoScaleFromTopLeft
End Sub
Sub RedimensionarGraficos010J()
    Columns("J:J").Select
    Application.CutCopyMode = False
    Charts.Add
    ActiveChart.ChartType = xlLineMarkers
    ActiveChart.SetSourceData Source:=Sheets("Plan1").Columns("J:J")
    ActiveChart.Location Where:=xlLocationAsObject, Name:="Plan1"
    ActiveSheet.Shapes("Gráfico 1").IncrementLeft -183.75
    ActiveSheet.Shapes("Gráfico 1").IncrementTop -105#
    ActiveSheet.Shapes("Gráfico 1").ScaleHeight 1.94, msoFalse, _
        msoScaleFromTopLeft
    ActiveSheet.Shapes("Gráfico 1").ScaleWidth 2.04, msoFalse, msoScaleFromTopLeft
End Sub

The 001, 002, 003, etc are just to help to identify each row.
I have recorded a macro, then repeat 120 times and fill with the help of excel, cut and paste, edit in a text editor, etc.
Then, I save as html and got all charts as images, what I really want.
But, this way, I must run one by one, 120 times!
It works, but @%%Y$%¨#*&(¨*%#!!!!!!!!
Just this, a tiny modification.
One of you could simplify this code, and in a way that I can choose how many rows I want to manage?

Viewing all articles
Browse latest Browse all 50079

Trending Articles