Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 32
Default Chart via Combo Box

I have the following macros set up to govern the operation of a chart, which
driven from a Combo Box. I've taken the code from an example I found but
cannot get it to run properly for me. If anyone has any help as to what's
wrong with it, that would be much appreciated. Thanks very much in advance.

Cheers

Mike


The code is as follows:

[NB: the Combo Box, located on the 'Direct Charting' worksheet, has macro
"DropDown_Change" assigned to it, and the "View Chart" macro is assigned to
a button on the 'Direct Data' worksheet.]



Sub ViewChart()
' Button click event handler
Dim StartRow As Long

' Display the chart for cursor position, if possible
If ActiveCell.Row 1 And ActiveCell.Row < 81 Then
StartRow = ActiveCell.Row
Else
StartRow = 2
End If

' Activate the Chart sheet
With Sheets("Direct Charting")
.Activate
End With

' Initialize the DropDown & update the chart
Charts(1).DropDowns(1).Value = StartRow - 1
Call UpdateChart(StartRow - 1)
End Sub




Sub DropDown_Change()
' NOTE: This dropdown is not an ActiveX control
' Update the chart, based on selected item
Dim ListIndex As Integer
ListIndex = Charts(1).DropDowns(1).Value
Call UpdateChart(ListIndex)
End Sub




Sub UpdateChart(Item)
' Updates the chart using the selected dropdown item
Dim TheChart As Chart
Dim DataSheet As Worksheet
Dim CatTitles As Range, SrcRange As Range
Dim SourceData As Range

Set TheChart = Sheets("Direct Charting")
Set DataSheet = Sheets("Direct Data")

With DataSheet
Set CatTitles = .Range("A2:E2")
Set SrcRange = .Range(.Cells(Item + 2, 1), _
.Cells(Item + 2, 5))
End With
Set SourceData = Union(CatTitles, SrcRange)

With TheChart
.SetSourceData Source:=SourceData, PlotBy:=xlRows
.ChartTitle.Left = TheChart.ChartArea.Left
.Deselect
End With
End Sub






  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6,582
Default Chart via Combo Box

Mike -

I have some examples on my web site that use the combobox without
requiring macros:

http://peltiertech.com/Excel/Charts/ChartByControl.html

- Jon
-------
Jon Peltier, Microsoft Excel MVP
Peltier Technical Services
http://PeltierTech.com/Excel/Charts/
_______

Mike wrote:

I have the following macros set up to govern the operation of a chart, which
driven from a Combo Box. I've taken the code from an example I found but
cannot get it to run properly for me. If anyone has any help as to what's
wrong with it, that would be much appreciated. Thanks very much in advance.

Cheers

Mike


The code is as follows:

[NB: the Combo Box, located on the 'Direct Charting' worksheet, has macro
"DropDown_Change" assigned to it, and the "View Chart" macro is assigned to
a button on the 'Direct Data' worksheet.]



Sub ViewChart()
' Button click event handler
Dim StartRow As Long

' Display the chart for cursor position, if possible
If ActiveCell.Row 1 And ActiveCell.Row < 81 Then
StartRow = ActiveCell.Row
Else
StartRow = 2
End If

' Activate the Chart sheet
With Sheets("Direct Charting")
.Activate
End With

' Initialize the DropDown & update the chart
Charts(1).DropDowns(1).Value = StartRow - 1
Call UpdateChart(StartRow - 1)
End Sub




Sub DropDown_Change()
' NOTE: This dropdown is not an ActiveX control
' Update the chart, based on selected item
Dim ListIndex As Integer
ListIndex = Charts(1).DropDowns(1).Value
Call UpdateChart(ListIndex)
End Sub




Sub UpdateChart(Item)
' Updates the chart using the selected dropdown item
Dim TheChart As Chart
Dim DataSheet As Worksheet
Dim CatTitles As Range, SrcRange As Range
Dim SourceData As Range

Set TheChart = Sheets("Direct Charting")
Set DataSheet = Sheets("Direct Data")

With DataSheet
Set CatTitles = .Range("A2:E2")
Set SrcRange = .Range(.Cells(Item + 2, 1), _
.Cells(Item + 2, 5))
End With
Set SourceData = Union(CatTitles, SrcRange)

With TheChart
.SetSourceData Source:=SourceData, PlotBy:=xlRows
.ChartTitle.Left = TheChart.ChartArea.Left
.Deselect
End With
End Sub







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
Combo chart? Joe M. Excel Discussion (Misc queries) 1 May 30th 08 01:00 PM
combo chart Doug W Charts and Charting in Excel 4 January 26th 07 04:17 AM
Create a combo chart with two of the same chart types Mark Parent Charts and Charting in Excel 2 October 14th 05 01:28 AM
Bar-Line Combo Chart mjamromi Charts and Charting in Excel 4 June 3rd 05 12:55 PM
combo chart JS Charts and Charting in Excel 3 May 18th 05 05:47 PM


All times are GMT +1. The time now is 10:42 AM.

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

About Us

"It's about Microsoft Excel"