View Single Post
  #4   Report Post  
Posted to microsoft.public.excel.programming
Bill Renaud Bill Renaud is offline
external usenet poster
 
Posts: 417
Default Macro to slightly modify the subroutine

<<...myformula1 and myformula2 correspond to column A of sheet1...

Where are "myformula1" and "myformula2" in your code?

Also, what to you mean by "to correspond to" in your post?

I made a few slight revisions in your code (mostly to use With statements).
The statement to set Range("F6") to a Sum was missing a period in front of
Range. You still need to take "Sheet3" out somehow, but I don't have your
data, so that I can run the macro to see what it does exactly.

I notice that you delete all of the embedded charts, then basically rebuild
them (or at least rebuild 1 of them). I wonder if that's really necessary.

'----------------------------------------------------------------------
Public Sub command2()
Dim wsActive As Worksheet
Dim shp As Shape
Dim i As Double
Dim j As Double

Set wsActive = ActiveSheet

For Each shp In wsActive.Shapes
If shp.Type = msoChart Then
shp.Delete
End If
Next shp

Charts.Add
With ActiveChart
.ChartType = xlColumnClustered
.SetSourceData Source:=wsActive.Range("H4"), _
PlotBy:=xlColumns
.SeriesCollection.NewSeries
End With 'ActiveChart

With wsActive
i = .Range("F4").Value
j = i + 3

ActiveChart.SeriesCollection(1).XValues = _
.Range(.Cells(2, 1), .Cells(j, 1))
ActiveChart.SeriesCollection(1).Values = _
.Range(.Cells(2, 2), .Cells(j, 2))
.Range("F6").Value = Application.WorksheetFunction _
.Sum(.Range(.Cells(2, 2), .Cells(j, 2)))
End With 'wsActive

With ActiveChart
.SeriesCollection(1).Name = wsActive.Range("A1").Value
.Legend.Delete
.Location Whe=xlLocationAsObject, Name:="Sheet3"
End With 'ActiveChart
'must be made generic later

For Each shp In wsActive.Shapes
If shp.Type = msoChart _
Then
With shp
.IncrementLeft -47.25
.IncrementTop -1.5
.ScaleWidth 1.6, msoFalse, msoScaleFromTopLeft
.ScaleHeight 1.46, msoFalse, msoScaleFromTopLeft
ActiveChart.Axes(xlCategory).TickLabels.NumberForm at = "0.00"
End With 'shp
End If
Next shp
End Sub

--
Regards,
Bill Renaud