U
ucanalways
The following code does not work in public sub. When I placed the code
in a public sub, I replaced Sheet3 in the following code with
"activesheet". All I am trying to do is make the code generic so that
I can used for any activesheet instead of a specific sheet. Frankly, I
dont know how to do this. Can anyone please give me the generic code
(public sub code) for the code given below. I tried doing this but
spiliting of hairs for more than couple of hours due to mysteroius
errors. I would deeply appreciate any help. Thank you very much
Private Sub CommandButton2_Click()
Dim shp As Shape
For Each shp In ActiveSheet.Shapes
If shp.Type = msoChart Then
shp.Delete
End If
Next shp
Dim i As Double
Dim j As Double
Charts.Add
ActiveChart.ChartType = xlColumnClustered
ActiveChart.SetSourceData Source:=Sheets("Sheet3").Range("H4"),
PlotBy:= _
xlColumns 'change required
ActiveChart.SeriesCollection.NewSeries
i = Range("F4").Value 'change required??
j = i + 3
With Sheets("Sheet3") 'change required
ActiveChart.SeriesCollection(1).XValues = _
.Range(.Cells(2, 1), .Cells(j, 1))
End With
With Sheets("Sheet3") 'change required
ActiveChart.SeriesCollection(1).Values = _
.Range(.Cells(2, 2), .Cells(j, 2))
End With
With Sheets("Sheet3") 'change required
Range("F6").Value =
Application.WorksheetFunction.Sum(.Range(.Cells(2, 2), .Cells(j, 2)))
End With
ActiveChart.SeriesCollection(1).Name = "=Sheet3!R1C2"
ActiveChart.Legend.Select
Selection.Delete
ActiveChart.Location Where:=xlLocationAsObject, Name:="Sheet3"
'Dim shp As Shape
For Each shp In ActiveSheet.Shapes
If shp.Type = msoChart Then
shp.IncrementLeft -47.25
shp.IncrementTop -1.5
shp.ScaleWidth 1.6, msoFalse, msoScaleFromTopLeft
shp.ScaleHeight 1.46, msoFalse, msoScaleFromTopLeft
ActiveChart.Axes(xlCategory).Select
Selection.TickLabels.NumberFormat = "0.00"
End If
Next shp
End Sub
in a public sub, I replaced Sheet3 in the following code with
"activesheet". All I am trying to do is make the code generic so that
I can used for any activesheet instead of a specific sheet. Frankly, I
dont know how to do this. Can anyone please give me the generic code
(public sub code) for the code given below. I tried doing this but
spiliting of hairs for more than couple of hours due to mysteroius
errors. I would deeply appreciate any help. Thank you very much
Private Sub CommandButton2_Click()
Dim shp As Shape
For Each shp In ActiveSheet.Shapes
If shp.Type = msoChart Then
shp.Delete
End If
Next shp
Dim i As Double
Dim j As Double
Charts.Add
ActiveChart.ChartType = xlColumnClustered
ActiveChart.SetSourceData Source:=Sheets("Sheet3").Range("H4"),
PlotBy:= _
xlColumns 'change required
ActiveChart.SeriesCollection.NewSeries
i = Range("F4").Value 'change required??
j = i + 3
With Sheets("Sheet3") 'change required
ActiveChart.SeriesCollection(1).XValues = _
.Range(.Cells(2, 1), .Cells(j, 1))
End With
With Sheets("Sheet3") 'change required
ActiveChart.SeriesCollection(1).Values = _
.Range(.Cells(2, 2), .Cells(j, 2))
End With
With Sheets("Sheet3") 'change required
Range("F6").Value =
Application.WorksheetFunction.Sum(.Range(.Cells(2, 2), .Cells(j, 2)))
End With
ActiveChart.SeriesCollection(1).Name = "=Sheet3!R1C2"
ActiveChart.Legend.Select
Selection.Delete
ActiveChart.Location Where:=xlLocationAsObject, Name:="Sheet3"
'Dim shp As Shape
For Each shp In ActiveSheet.Shapes
If shp.Type = msoChart Then
shp.IncrementLeft -47.25
shp.IncrementTop -1.5
shp.ScaleWidth 1.6, msoFalse, msoScaleFromTopLeft
shp.ScaleHeight 1.46, msoFalse, msoScaleFromTopLeft
ActiveChart.Axes(xlCategory).Select
Selection.TickLabels.NumberFormat = "0.00"
End If
Next shp
End Sub