Help with Excel 5 Macro (Visual Basic)

Help with Excel 5 Macro (Visual Basic)

Post by Jan M.L. STANKOVSK » Mon, 15 Apr 1996 04:00:00



Hello

I've recorded a macro to produce a chart of a range of numbers (select
range, call chardwizard)
This is the macro:
Sub Macro12()
    ActiveCell.Range("A1:K11").Select
    ActiveSheet.ChartObjects.Add(95.25, 13.5, 145.5, 116.25).Select
    Application.CutCopyMode = False
    ActiveChart.ChartWizard Source:=Range("A2:K12"), Gallery:= _
        xl3DSurface, Format:=3, PlotBy:=xlRows, CategoryLabels:=1, _
       SeriesLabels:=1, HasLegend:=2, Title:="", CategoryTitle:="", _
     ValueTitle:="", ExtraTitle:=""
End Sub

When I try to apply this macro to the next set of numbers the selection
is done right BUT the chartwizard uses the same numbers as in the old
selection (the one I recorded the macro with) as input data.

So how do i tell the chartwizard to use the actual selection ??

Please help I need 40 Charts, and I hoped a macro will make it easier !!

Thanks


 
 
 

Help with Excel 5 Macro (Visual Basic)

Post by Johan Skug » Mon, 15 Apr 1996 04:00:00



>Hello
>I've recorded a macro to produce a chart of a range of numbers (select
>range, call chardwizard)
>This is the macro:
>Sub Macro12()
>    ActiveCell.Range("A1:K11").Select
>    ActiveSheet.ChartObjects.Add(95.25, 13.5, 145.5, 116.25).Select
>    Application.CutCopyMode = False
>    ActiveChart.ChartWizard Source:=Range("A2:K12"), Gallery:= _
>        xl3DSurface, Format:=3, PlotBy:=xlRows, CategoryLabels:=1, _
>       SeriesLabels:=1, HasLegend:=2, Title:="", CategoryTitle:="", _
>     ValueTitle:="", ExtraTitle:=""
>End Sub
>When I try to apply this macro to the next set of numbers the selection
>is done right BUT the chartwizard uses the same numbers as in the old
>selection (the one I recorded the macro with) as input data.
>So how do i tell the chartwizard to use the actual selection ??
>Please help I need 40 Charts, and I hoped a macro will make it easier !!
>Thanks


Try this instead:

Sub MakeChart()
    Range(Activecell.Offset(1,0).Address &":"& _
       ActiveCell.Offset(Selection.Rows.Count-2, _
       Selection.Columns.Count-1).Address).Select
    set TheValues = Selection
    ActiveSheet.ChartObjects.Add(95.25, 13.5, 145.5, 116.25).Select
    Application.CutCopyMode = False
    ActiveChart.ChartWizard Source:=TheValues.Address, Gallery:= _
        xl3DSurface, Format:=3, PlotBy:=xlRows, CategoryLabels:=1, _
       SeriesLabels:=1, HasLegend:=2, Title:="", CategoryTitle:="", _
     ValueTitle:="", ExtraTitle:=""
End Sub

Hope it helps!

/Johan Skugge

--

     (o o)      | phone: (int) +46-8-7149556 (nat) 08-7149556
-oOO--(_)--OOo- | snail: Johan Skugge; Bohusg 43, 9; 116 67 Sthlm; Sweden