PC Review


Reply
Thread Tools Rate Thread

Define a chart using VBA

 
 
Pim
Guest
Posts: n/a
 
      27th Sep 2005

Hi folks,
I'm baffled- I'm writing a macro to pull a data table into an excel
sheet & create a bargraph of those results. The number of records in
the data table are variable (say between 2 and 50).

I'm trying to define a dynamic bar graph using VBA. The X values are
in col C and the text Y vlaues are in col A. (both start in row 3) The
values in column B are necessary, but have nothing to do with the
graph. I'm having trouble using variables to define the source data as
two, non adjacent ranges.

I've had problems just including the 50 cells in the data table as it
includes blank
spaces in the chart.

The code below builds the graph based on the X values starting in cell
C3. It just numbers them on the Y axis, not by the corresponding text
values....

Any ideas?
Thanks
pim

Dim sheetName as String 'name of the sheet where the data table
Dim NoRec As Double 'Number of records returned in query
Dim Graph As ChartObject 'Bar graph

NoRec = Application.WorksheetFunction.CountA(Columns("A:A"))
Set Graph = ActiveSheet.ChartObjects.Add _
(Left:=285, Width:=548, Top:=40, Height:=825)
Graph.Chart.SetSourceData
Source:=Sheets(sheetName).Range(Cells(3, 3), Cells(NoRec, 3))

Graph.Chart.ChartType = xlBarClustered
ActiveSheet.ChartObjects(1).Activate

ActiveChart.HasLegend = False
ActiveChart.HasTitle = False
With ActiveChart.ChartGroups(1)
..Overlap = 0
..GapWidth = 140
..HasSeriesLines = False
End With
With ActiveChart.ChartGroups(1)
..Overlap = 0
..GapWidth = 140
..HasSeriesLines = False
End With
'Y axis- text names format
With ActiveChart.Axes(xlCategory)
..CrossesAt = 1
..TickLabelSpacing = 1
..TickMarkSpacing = 1
..AxisBetweenCategories = True
..ReversePlotOrder = True
..MajorTickMark = xlOutside
..MinorTickMark = xlNone
..TickLabelPosition = xlLow
End With
'X axis-PI values Format
With ActiveChart.Axes(xlValue)
..TickLabelPosition = xlHigh
End With
ActiveChart.PlotArea.Select
With Selection.Border
..ColorIndex = 16
..Weight = xlThin
..LineStyle = xlContinuous
End With


--
Pim
------------------------------------------------------------------------
Pim's Profile: http://www.excelforum.com/member.php...o&userid=27565
View this thread: http://www.excelforum.com/showthread...hreadid=470956

 
Reply With Quote
 
 
 
 
Pim
Guest
Posts: n/a
 
      27th Sep 2005

i got it- thanks guys!


--
Pim
------------------------------------------------------------------------
Pim's Profile: http://www.excelforum.com/member.php...o&userid=27565
View this thread: http://www.excelforum.com/showthread...hreadid=470956

 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Name to define a chart range mge Microsoft Excel Misc 6 14th May 2009 06:31 PM
Name to define a chart range mge Microsoft Excel Misc 0 13th May 2009 09:03 PM
Trying to define a changing range for chart Rcarper Microsoft Excel Charting 2 14th Jan 2009 03:50 PM
Define Chart Name??? hce Microsoft Excel Misc 1 18th Sep 2004 12:27 PM
Define Chart Name??? hce Microsoft Excel Misc 10 17th Sep 2004 01:20 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 01:57 PM.