Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default how to make chart on selected range?

I have the following code, almost got what I want, but each time I run
it, it says: run time error 13, type mismatch.

do you know what went wrong? thanksssssss........



Sub AddChart()
Dim chtChart As Chart
Dim Myrange As Range

ActiveSheet.ChartObjects.Delete
'Create a new chart.
Set chtChart = Charts.Add
Set chtChart = chtChart.Location(Whe=xlLocationAsObject,
Name:="Sheet2")
Set Myrange = Selection

With chtChart
.ChartType = xlColumnClustered
'Set data source range.
.SetSourceData Source:=Sheets("Sheet2").Myrange, PlotBy:= _
xlRows
.HasTitle = True
.ChartTitle.Text = "=Sheet2!R1C1"
'The Parent property is used to set properties of
'the Chart.
With .Parent
.Top = Range("F9").Top
.Left = Range("F9").Left
.Name = "ToolsChart2"
End With
End With
End Sub

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 49
Default how to make chart on selected range?

Hi

If you change your code slightly it will work OK. The range you
selected becomes unselected when you delete the chart, so you need to
select it again. This can be done by declaring your range up front
and selecting it later.

Take care

Chad


Sub AddChart()
Dim chtChart As Chart
Dim Myrange As Range

Set Myrange = Selection
ActiveSheet.ChartObjects.Delete
'Create a new chart.
Set chtChart = Charts.Add
Set chtChart = chtChart.Location(Whe=xlLocationAsObject,
Name:="Sheet2")
Myrange.Select

With chtChart
.ChartType = xlColumnClustered
'Set data source range.
'.SetSourceData Source:=Sheets("Sheet2").Myrange,
PlotBy:=xlColumns
.SetSourceData Source:=Myrange, PlotBy:=xlRows
.HasTitle = True
.ChartTitle.Text = "=Sheet2!R1C1"
'The Parent property is used to set properties of
'the Chart.
With .Parent
.Top = Range("F9").Top
.Left = Range("F9").Left
.Name = "ToolsChart2"
End With
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
can i edit only a selected range of data in an excel chart? aarho Charts and Charting in Excel 1 December 2nd 09 09:27 PM
dynamic chart on user selected data range in Excel 2007 turen Charts and Charting in Excel 5 September 1st 07 02:03 AM
How can i make a chart to show range and median ? John Abercrombie Charts and Charting in Excel 1 June 28th 06 12:28 AM
how do i make it so that when a sheat is selected either via link or tab, that xlLastCell is selected. the last on the sheet. Daniel Excel Worksheet Functions 1 July 12th 05 01:30 AM
plotting chart with user selected range from current workbook annette2002 Excel Programming 0 June 5th 04 03:16 AM


All times are GMT +1. The time now is 07:33 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"