Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Microsoft Office > Excel VBA > Excel VBA
| Search | Today's Posts | Mark Forums Read
Excel VBA Discuss using VBA for Excel programming.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Excel VBA section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old August 21st, 2009, 12:13 AM
Authorized User
 
Join Date: Mar 2008
Location: , , Russia.
Posts: 74
Thanks: 2
Thanked 0 Times in 0 Posts
Send a message via ICQ to sektor
Default Creating chart problem [Excel 2007]

I wanna create an empty chart with the following code, but it fails. Compiler says "Type mismatch" on "Set ch..." line. What is wrong?


Here's code:

Code:
Dim ch As ChartObject
Set ch = Me.Shapes.AddChart
ch.Chart.SetSourceData Source:=Range("Sheet1!$A$10:$B$14"), PlotBy:= xlColumns
ch.Chart.ChartType = xlColumnStacked
 
Old August 25th, 2009, 07:11 PM
Friend of Wrox
Points: 513, Level: 8
Points: 513, Level: 8 Points: 513, Level: 8 Points: 513, Level: 8
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Feb 2007
Location: Davenport, IA, USA.
Posts: 163
Thanks: 0
Thanked 2 Times in 2 Posts
Default

Try this sample:

Code:
Public Sub addchart()

'This sample adds a chart to the current sheet.  The named parameters will hopefully make it easier to understand.
  Dim ch As ChartObject, iLeft As Integer, iTop As Integer, iWidth As Integer, iHeight As Integer
  iLeft = 25
  iTop = 10
  iWidth = 200
  iHeight = 100
  Set ch = ActiveSheet.ChartObjects.Add(iLeft, iTop, iWidth, iHeight)
  ch.Chart.SetSourceData Source:=Range("Sheet1!$A$10:$B$14"), PlotBy:=xlColumns
  ch.Chart.ChartType = xlColumnStacked

End Sub
Hope this helps point in the right direction.
The Following User Says Thank You to allenm For This Useful Post:
sektor (September 3rd, 2009)




Similar Threads
Thread Thread Starter Forum Replies Last Post
Help! Conversion Excel 2003 VBA codes to Excel 2007 sunny76 BOOK: Excel 2007 VBA Programmer's Reference ISBN: 978-0-470-04643-2 0 August 13th, 2009 05:38 AM
2007 Chart problem markejackson02 Excel VBA 0 June 19th, 2009 10:39 AM
DropDown control problem [Excel 2007] sektor BOOK: Excel 2007 VBA Programmer's Reference ISBN: 978-0-470-04643-2 0 May 13th, 2009 06:20 AM
DropDown control problem [Excel 2007] sektor Excel VBA 0 May 13th, 2009 05:59 AM
Dropdown problem in excel 2007 Aker Excel VBA 1 October 31st, 2008 11:49 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.