Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 169
Default Dynamic Charting (StackedBar)

I've been working on this for a couple of days now, so bear with me. I've
got some data (linked from an Access query) that looks like:

Mission Day Sorties
A 1 9
A 2 7
A 3 5
B 1 10
B 2 11
B 3 19
C 1 5
C 2 16
C 3 12

The types of missions vary, as do the number of day (although for a
particular query, the number of day will be constant across each of the
missions). What I want to do is dynamically format the data series of a
stacked bar chart so that each of the Missions is a different data series,
the days are the X-Axis Values, and the Sorties reflect the height of the
bars in the stacked bar chart.

I'm relatively new to Excel VBA, but have been using Access for about 10
years. I'm just not familiar with the Excel object model. The first
problem I am having is actually selecting the chart so that I actually have
an "ActiveChart" object. Can anyone help me out with that step?

Once I have selected a chart, I want to clear out it's SeriesCollection;
figured out a way to do that one series at a time but would be interested in
knowing if that can be done in a single step.

Next, I assume I am going to have to do some looping to identify the start
and end point of each series (mission), but should probably start out by
clearing out the Series collections. Is there an easy way within Excel to
identify the row that contains the next value. For example, Mission type
"A" starts on Row 2, and mission type "B" starts on row 5. Is there a quick
way to identify Row 5 without looping through each row and testing the value
of the first cell in each row against some preset value? In most cases, my
dataset will contain around a thousand rows (5-10 mission types)

I assume that once I define the start and end positions of each series, I'll
be able to use code similiar to the following to build the series.

ActiveChart.SeriesCollection.NewSeries
ActiveChart.SeriesCollection(1).XValues = "=Sheet1!R2C2:R4C2"
ActiveChart.SeriesCollection(1).Values = "=Sheet1!R2C3:R4C3"
ActiveChart.SeriesCollection(1).Name = "=Sheet1!R2C1"

Any help would be greatly appreciated


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6,582
Default Dynamic Charting (StackedBar)

Do you need to do it in VBA? You could make a pivot table in Excel which
will produce a table with Days 1, 2, 3 down the first column and Missions A,
B, and C across the top row. This is ideally suited to creating a chart,
either a pivot chart or a regular chart:

http://pubs.logicalexpressions.com/P...cle.asp?ID=553

If you do want to use VBA, don't be afraid of looping. To clear out unwanted
series:

Sub RemoveUnwantedSeries()
With ActiveChart
Do Until .SeriesCollection.Count = 0
.SeriesCollection(1).Delete
Loop
End With
End Sub
(excerpted from http://peltiertech.com/Excel/ChartsH...kChartVBA.html,
which has a lot of other hints too).
To find the series, you start at the first row of mission data (row i1),
read what the mission is, and then read each row after that until you get to
a different value. This is row i2, so your series is defined as going from
i1 to i2-1. Build a string in R1C1 notation and use the code you posted.
Then set the new value of i1 equal to i2, and continue down your data.

While the looping may seem tedious, it's pretty fast. On a recent project I
used this system to create about 30 charts from a 1200 row worksheet.
Including adding a worksheet for each chart, putting some labels on the
sheet, creating the chart, and formatting it, the program build 30 charts in
under 5 seconds.

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


"Dale Fye" wrote in message
...
I've been working on this for a couple of days now, so bear with me. I've
got some data (linked from an Access query) that looks like:

Mission Day Sorties
A 1 9
A 2 7
A 3 5
B 1 10
B 2 11
B 3 19
C 1 5
C 2 16
C 3 12

The types of missions vary, as do the number of day (although for a
particular query, the number of day will be constant across each of the
missions). What I want to do is dynamically format the data series of a
stacked bar chart so that each of the Missions is a different data series,
the days are the X-Axis Values, and the Sorties reflect the height of the
bars in the stacked bar chart.

I'm relatively new to Excel VBA, but have been using Access for about 10
years. I'm just not familiar with the Excel object model. The first
problem I am having is actually selecting the chart so that I actually
have an "ActiveChart" object. Can anyone help me out with that step?

Once I have selected a chart, I want to clear out it's SeriesCollection;
figured out a way to do that one series at a time but would be interested
in knowing if that can be done in a single step.

Next, I assume I am going to have to do some looping to identify the start
and end point of each series (mission), but should probably start out by
clearing out the Series collections. Is there an easy way within Excel to
identify the row that contains the next value. For example, Mission type
"A" starts on Row 2, and mission type "B" starts on row 5. Is there a
quick way to identify Row 5 without looping through each row and testing
the value of the first cell in each row against some preset value? In
most cases, my dataset will contain around a thousand rows (5-10 mission
types)

I assume that once I define the start and end positions of each series,
I'll be able to use code similiar to the following to build the series.

ActiveChart.SeriesCollection.NewSeries
ActiveChart.SeriesCollection(1).XValues = "=Sheet1!R2C2:R4C2"
ActiveChart.SeriesCollection(1).Values = "=Sheet1!R2C3:R4C3"
ActiveChart.SeriesCollection(1).Name = "=Sheet1!R2C1"

Any help would be greatly appreciated



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 249
Default Dynamic Charting (StackedBar)

When I've needed to do this I rotate the table (crosstab query) in Access
before using the TransferSpreadsheet Method.

--

Regards,

Dave Patrick ....Please no email replies - reply in newsgroup.
Microsoft Certified Professional
Microsoft MVP [Windows]
http://www.microsoft.com/protect

"Dale Fye" wrote:
I've been working on this for a couple of days now, so bear with me. I've
got some data (linked from an Access query) that looks like:

Mission Day Sorties
A 1 9
A 2 7
A 3 5
B 1 10
B 2 11
B 3 19
C 1 5
C 2 16
C 3 12

The types of missions vary, as do the number of day (although for a
particular query, the number of day will be constant across each of the
missions). What I want to do is dynamically format the data series of a
stacked bar chart so that each of the Missions is a different data series,
the days are the X-Axis Values, and the Sorties reflect the height of the
bars in the stacked bar chart.

I'm relatively new to Excel VBA, but have been using Access for about 10
years. I'm just not familiar with the Excel object model. The first
problem I am having is actually selecting the chart so that I actually
have an "ActiveChart" object. Can anyone help me out with that step?

Once I have selected a chart, I want to clear out it's SeriesCollection;
figured out a way to do that one series at a time but would be interested
in knowing if that can be done in a single step.

Next, I assume I am going to have to do some looping to identify the start
and end point of each series (mission), but should probably start out by
clearing out the Series collections. Is there an easy way within Excel to
identify the row that contains the next value. For example, Mission type
"A" starts on Row 2, and mission type "B" starts on row 5. Is there a
quick way to identify Row 5 without looping through each row and testing
the value of the first cell in each row against some preset value? In
most cases, my dataset will contain around a thousand rows (5-10 mission
types)

I assume that once I define the start and end positions of each series,
I'll be able to use code similiar to the following to build the series.

ActiveChart.SeriesCollection.NewSeries
ActiveChart.SeriesCollection(1).XValues = "=Sheet1!R2C2:R4C2"
ActiveChart.SeriesCollection(1).Values = "=Sheet1!R2C3:R4C3"
ActiveChart.SeriesCollection(1).Name = "=Sheet1!R2C1"

Any help would be greatly appreciated


Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Dynamic charting widman Charts and Charting in Excel 2 October 26th 06 11:00 PM
Dynamic Charting stone-man Excel Programming 2 October 23rd 06 10:01 PM
Dynamic Charting - i think! [email protected] Charts and Charting in Excel 4 July 27th 06 09:33 AM
Dynamic Charting Richard Flame Charts and Charting in Excel 3 July 3rd 06 06:39 PM
Dynamic charting PicaJ Excel Programming 1 August 4th 04 09:57 PM


All times are GMT +1. The time now is 12:41 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"