PDA

View Full Version : vba to automatically update data and graphs



wedd
02-22-2012, 11:34 PM
Hi experts,

I was interested to find whether it is possible to update data with attach to a graph automatically using visual basic. If so, how can this be done? Do you have any sample code to illustrate how this can be done?



Thanks for your contributions:friends:

Bob Phillips
02-23-2012, 02:08 AM
It can be done. Give us a scenario, data etc., and we can show you. Otherwise Google it, I am sure there are loads of examples out there.

raji2678
02-23-2012, 11:13 PM
You can create charts. Hope this code will give you and idea. You can google for additional feauers or create a macro and observe the generated code.

ActiveSheet.Shapes.AddChart.Select
ActiveChart.Parent.Top = lngTopPosition
ActiveChart.Parent.Left = lngLeftPosition
ActiveChart.Parent.Width = 730
ActiveChart.Parent.Height = 250
ActiveChart.SetSourceData Source:=Range(strGraphRange), PlotBy:=xlColumns
ActiveChart.ChartType = xlLineMarkers
ActiveChart.Axes(xlCategory).HasTitle = True
ActiveChart.Axes(xlCategory, xlPrimary).AxisTitle.Text = strGraphOn
ActiveChart.Axes(xlCategory).Delete
ActiveChart.SetElement (msoElementChartTitleAboveChart)
ActiveChart.ChartTitle.Text = "Test Chart"
ActiveChart.Axes(xlValue).MajorGridlines.Delete
ActiveChart.Legend.Position = xlCorner
ActiveChart.Legend.LegendEntries(4).Delete
For intSeriesCounter = 1 To ActiveChart.SeriesCollection.Count
ActiveChart.SeriesCollection(intSeriesCounter).Border.ColorIndex = 4
ActiveChart.SeriesCollection(intSeriesCounter).MarkerStyle = -4142
next intSeriesCounter