View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.charting
LINDA LINDA is offline
external usenet poster
 
Posts: 205
Default how to create a chart from a dynamic table of data?

meaning that doesn't need the looping statement?so,how to i check the size of
table that used to generate the chart?

"Jon Peltier" wrote:

Use the macro recorder as a guide. When I record a macro to create a simple
chart it looks like:

Sub Macro1()
' Macro recorded 7/30/2007 by Jon Peltier
'
Charts.Add
ActiveChart.ChartType = xlColumnClustered
ActiveChart.SetSourceData Source:=Sheets("Sheet1").Range("A1:C6")
ActiveChart.Location Whe=xlLocationAsObject, Name:="Sheet1"
End Sub

Assuming your DB dump is on a new sheet, and applying some cleanup, this is
a workable macro:

Sub DB_Dump_to_Chart()
Dim rChartData As Range
Dim wsData As Worksheet

Set wsData = ActiveSheet
Set rChartData = wsData.UsedRange

Charts.Add
ActiveChart.ChartType = xlColumnClustered
ActiveChart.SetSourceData Source:=rChartData
ActiveChart.Location Whe=xlLocationAsObject, Name:=wsData.Name
End Sub

Naturally your recorded macro will be different, since you will record your
actions while creating the type of chart you want from the data. But make
the same kind of adjustments as I have made, and you should get a reasonable
macro.

For more on fixing up chart macros:

http://peltiertech.com/Excel/ChartsH...kChartVBA.html

- Jon
-------
Jon Peltier, Microsoft Excel MVP
Tutorials and Custom Solutions
Peltier Technical Services, Inc. - http://PeltierTech.com
_______


"linda" wrote in message
...
hai!!
i need to create a chart from a dynamic table,meaning that the table is
auto-generated from database after clicking a button.This is my first time
using macro in excel, so i'm not really well in it.
my idea right now is using Chart.Add,but then i'm having problem on how to
define the cells selection(i must do "the do..loop statement" rite?)
ur help is very appreciated,tq!