LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Setting Source Range For Chart

Try it like this:

Dim LastDataRow As Long
LastDataRow = Cells(Rows.Count, "C").End(xlUp).Row
If LastDataRow = 1 Then
GoTo MyErrorHandler
Else
Sheets("InputSheet").Visible = False
Sheets("Chart1").Visible = True
Sheets("Chart1").Select

With ActiveChart
Set Sh = Workbooks("Main.xls").Sheets("DataSheet")
.SetSourceData Source:=Workbooks("Main.xls"). _
Sh.Range(Sh.Range("C1"), Sh.Range("H" & LastDataRow)), _
PlotBy:=xlColumns
.HasTitle = True
.ChartTitle.Characters.Text = "Chart"
.Axes(xlValue, xlPrimary).HasTitle = True
.Axes(xlValue, xlPrimary).AxisTitle.Characters.Text = "Percentage"
.HasAxis(xlCategory, xlPrimary) = True
.HasAxis(xlValue, xlPrimary) = True
.Axes(xlCategory, xlPrimary).CategoryType = xlAutomatic
.HasLegend = False
.HasDataTable = True
.DataTable.ShowLegendKey = True
End With
End If
Exit Sub

MyErrorHandler:
'"Whole bunch of stuff here"
End Sub

--
Regards,
Tom Ogilvy

"James Stephens" wrote in message
...
I have this macro basically done, I am having a problem with settign the

source range for the chart though. I think it is simply a syntax error but
I am not sure - any advice would be helpful as I am stuck. Here is the part
of the code:

Dim LastDataRow As Long
LastDataRow = Cells(Rows.Count, "C").End(xlUp).Row
If LastDataRow = 1 Then GoTo MyErrorHandler
Else
Sheets("InputSheet").Visible = False
Sheets("Chart1").Visible = True
Sheets("Chart1").Select

With ActiveChart
.SetSourceData

Source:=Workbooks("Main.xls").Sheets("DataSheet"). Range("C1", Range("H" &
LastDataRow)), _
PlotBy:=xlColumns
.HasTitle = True
.ChartTitle.Characters.Text = "Chart"
.Axes(xlValue, xlPrimary).HasTitle = True
.Axes(xlValue, xlPrimary).AxisTitle.Characters.Text = "Percentage"
.HasAxis(xlCategory, xlPrimary) = True
.HasAxis(xlValue, xlPrimary) = True
.Axes(xlCategory, xlPrimary).CategoryType = xlAutomatic
.HasLegend = False
.HasDataTable = True
.DataTable.ShowLegendKey = True
End With
End If
Exit Sub

MyErrorHandler:
'"Whole bunch of stuff here"
End Sub

I am getting the error "Mehtod 'Range' of Object '_Global' Failed" on the

..SetSourceData command. And I get some problems with my "if" and "else"
statements. What am I doing wrong - looking at it, it should work, I just
don't know where I am going wrong.

Thanks for any advice,

Jim



 
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
Using a named range as a data source for a chart MichaelR Charts and Charting in Excel 4 June 16th 08 04:15 AM
Problem setting SeriesCollections source range Lead Foot Charts and Charting in Excel 2 January 27th 06 05:11 AM
Setting source data range with Charts D Charts and Charting in Excel 2 January 1st 06 02:51 AM
Setting the range in a chart using VB Torben Laursen Excel Programming 1 March 3rd 04 02:16 PM
change chart source from range to raw data daithimcc Excel Programming 2 December 27th 03 05:19 PM


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