Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 155
Default Macro for Graph - problem with Range

Could someone please help me with the following code

Because my list changes with new entries I need the macro to identify the
correct range. I did try substituting Range("B10:G13")
with .ActiveCell and all combinations I have tried receive the following error

Run-time error '438'
Object doesn't support this property or method

Is there another line I need to add to this code for it to recognise the end
of the data table?

Sub Macro9()
'
' Macro9 Macro
' Macro recorded 3/03/2007 by Tanya
'
'
Range("Header").Select
Charts.Add
ActiveChart.ChartType = xlLineMarkersStacked
'Difficulty with next line of code - problem with Range as area changes with
new entries in list
ActiveChart.SetSourceData Source:=Sheets("Sheet1").Range("B10:G13"),
PlotBy _
:=xlRows
ActiveChart.Location Whe=xlLocationAsObject, Name:="Sheet1"
With ActiveChart
.HasTitle = True
.ChartTitle.Characters.Text = "Daily Hours Worked"
.Axes(xlCategory, xlPrimary).HasTitle = True
.Axes(xlCategory, xlPrimary).AxisTitle.Characters.Text = "Day of Week"
.Axes(xlValue, xlPrimary).HasTitle = True
.Axes(xlValue, xlPrimary).AxisTitle.Characters.Text = "Hours worked"
End With
With ActiveChart
.HasAxis(xlCategory, xlPrimary) = True
.HasAxis(xlValue, xlPrimary) = True
End With
ActiveChart.Axes(xlCategory, xlPrimary).CategoryType = xlAutomatic
With ActiveChart.Axes(xlCategory)
.HasMajorGridlines = False
.HasMinorGridlines = False
End With
With ActiveChart.Axes(xlValue)
.HasMajorGridlines = True
.HasMinorGridlines = False
End With
ActiveChart.HasDataTable = False


End Sub

  #2   Report Post  
Posted to microsoft.public.excel.programming
Jay Jay is offline
external usenet poster
 
Posts: 671
Default Macro for Graph - problem with Range

Add these two lines before Range("Header").select:
Dim chartrange As Range
Set chartrange = Range(Range("B10"), Range("G10").End(xlDown))

Then, adjust your problem statement with the following line:
ActiveChart.SetSourceData Source:=chartrange, PlotBy:=xlRows

--
Jay


"Tanya" wrote:

Could someone please help me with the following code

Because my list changes with new entries I need the macro to identify the
correct range. I did try substituting Range("B10:G13")
with .ActiveCell and all combinations I have tried receive the following error

Run-time error '438'
Object doesn't support this property or method

Is there another line I need to add to this code for it to recognise the end
of the data table?

Sub Macro9()
'
' Macro9 Macro
' Macro recorded 3/03/2007 by Tanya
'
'
Range("Header").Select
Charts.Add
ActiveChart.ChartType = xlLineMarkersStacked
'Difficulty with next line of code - problem with Range as area changes with
new entries in list
ActiveChart.SetSourceData Source:=Sheets("Sheet1").Range("B10:G13"),
PlotBy _
:=xlRows
ActiveChart.Location Whe=xlLocationAsObject, Name:="Sheet1"
With ActiveChart
.HasTitle = True
.ChartTitle.Characters.Text = "Daily Hours Worked"
.Axes(xlCategory, xlPrimary).HasTitle = True
.Axes(xlCategory, xlPrimary).AxisTitle.Characters.Text = "Day of Week"
.Axes(xlValue, xlPrimary).HasTitle = True
.Axes(xlValue, xlPrimary).AxisTitle.Characters.Text = "Hours worked"
End With
With ActiveChart
.HasAxis(xlCategory, xlPrimary) = True
.HasAxis(xlValue, xlPrimary) = True
End With
ActiveChart.Axes(xlCategory, xlPrimary).CategoryType = xlAutomatic
With ActiveChart.Axes(xlCategory)
.HasMajorGridlines = False
.HasMinorGridlines = False
End With
With ActiveChart.Axes(xlValue)
.HasMajorGridlines = True
.HasMinorGridlines = False
End With
ActiveChart.HasDataTable = False


End Sub

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 155
Default Macro for Graph - problem with Range

Thank you very much Jay, it worked a charm.

Kind Regards
Tanya

"Jay" wrote:

Add these two lines before Range("Header").select:
Dim chartrange As Range
Set chartrange = Range(Range("B10"), Range("G10").End(xlDown))

Then, adjust your problem statement with the following line:
ActiveChart.SetSourceData Source:=chartrange, PlotBy:=xlRows

--
Jay


"Tanya" wrote:

Could someone please help me with the following code

Because my list changes with new entries I need the macro to identify the
correct range. I did try substituting Range("B10:G13")
with .ActiveCell and all combinations I have tried receive the following error

Run-time error '438'
Object doesn't support this property or method

Is there another line I need to add to this code for it to recognise the end
of the data table?

Sub Macro9()
'
' Macro9 Macro
' Macro recorded 3/03/2007 by Tanya
'
'
Range("Header").Select
Charts.Add
ActiveChart.ChartType = xlLineMarkersStacked
'Difficulty with next line of code - problem with Range as area changes with
new entries in list
ActiveChart.SetSourceData Source:=Sheets("Sheet1").Range("B10:G13"),
PlotBy _
:=xlRows
ActiveChart.Location Whe=xlLocationAsObject, Name:="Sheet1"
With ActiveChart
.HasTitle = True
.ChartTitle.Characters.Text = "Daily Hours Worked"
.Axes(xlCategory, xlPrimary).HasTitle = True
.Axes(xlCategory, xlPrimary).AxisTitle.Characters.Text = "Day of Week"
.Axes(xlValue, xlPrimary).HasTitle = True
.Axes(xlValue, xlPrimary).AxisTitle.Characters.Text = "Hours worked"
End With
With ActiveChart
.HasAxis(xlCategory, xlPrimary) = True
.HasAxis(xlValue, xlPrimary) = True
End With
ActiveChart.Axes(xlCategory, xlPrimary).CategoryType = xlAutomatic
With ActiveChart.Axes(xlCategory)
.HasMajorGridlines = False
.HasMinorGridlines = False
End With
With ActiveChart.Axes(xlValue)
.HasMajorGridlines = True
.HasMinorGridlines = False
End With
ActiveChart.HasDataTable = False


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
macro problem: range offset question lacy Excel Discussion (Misc queries) 6 September 4th 09 03:31 PM
Range R1C1 notation & the problem with my Macro skiptabor Excel Programming 2 May 31st 05 02:05 PM
Problem with named range as VBA macro parameter Ken[_11_] Excel Programming 4 March 5th 04 02:16 PM
Excel Macro Problem, Add-in need to work in every workbook & Error:9 Subscript out of range Burak[_2_] Excel Programming 1 October 31st 03 08:09 PM


All times are GMT +1. The time now is 01:54 PM.

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"