Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 24
Default need help in my code on generating chart with dynamic range

Hi

I have some trouble with my code such that the source range will be
dynamic
Hopping that someone can enlighten my code, i have tried to debug but
can't get it to work.

Sub tapeagechart()

Dim ws As Worksheet
Dim rng As Range, rng1 As Range
Dim iRow As Long

Set ws = Worksheets("Sheet2")

'find last row
With ws
iRow = .Range("A" & Rows.Count).End(xlUp).Row
Set rng = .Range("A18:A" & iRow)
rng.Name = "names"
End With

Set rng1 = ws.Range("C18:C" & iRow)
rng1.Name = "result"


Charts.Add
ActiveChart.ChartType = xlLineMarkers
ActiveChart.SetSourceData Source:=Sheets("Sheet2").Range(?????) _
PlotBy:=xlColumns

i am having trouble in this line, i not sure what should i put
in ?????,
i tried putting the range name Range("names" ,"result") but it failed
this range will change according to my data

or i should use serial instead of setsourcedata source?


ActiveChart.Location Whe=xlLocationAsObject, Name:="Sheet2"

With ActiveChart
.HasTitle = True
.ChartTitle.Characters.Text = "Chart of Tape Age Summary"
.Axes(xlCategory).TickLabels.Orientation = xlUpward
With .Parent
.Top = Range("F18").Top
.Left = Range("F18").Left
.Name = "tapeage"
End With
End With

End Sub


thank you

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 244
Default need help in my code on generating chart with dynamic range

should just need "Result" as that is the named range, although rng1
without quotes would probably work just as well!
On 30 May, 08:59, kiwis wrote:
Hi

I have some trouble with my code such that the source range will be
dynamic
Hopping that someone can enlighten my code, i have tried to debug but
can't get it to work.

Sub tapeagechart()

Dim ws As Worksheet
Dim rng As Range, rng1 As Range
Dim iRow As Long

Set ws = Worksheets("Sheet2")

'find last row
With ws
iRow = .Range("A" & Rows.Count).End(xlUp).Row
Set rng = .Range("A18:A" & iRow)
rng.Name = "names"
End With

Set rng1 = ws.Range("C18:C" & iRow)
rng1.Name = "result"

Charts.Add
ActiveChart.ChartType = xlLineMarkers
ActiveChart.SetSourceData Source:=Sheets("Sheet2").Range(?????) _
PlotBy:=xlColumns

i am having trouble in this line, i not sure what should i put
in ?????,
i tried putting the range name Range("names" ,"result") but it failed
this range will change according to my data

or i should use serial instead of setsourcedata source?

ActiveChart.Location Whe=xlLocationAsObject, Name:="Sheet2"

With ActiveChart
.HasTitle = True
.ChartTitle.Characters.Text = "Chart of Tape Age Summary"
.Axes(xlCategory).TickLabels.Orientation = xlUpward
With .Parent
.Top = Range("F18").Top
.Left = Range("F18").Left
.Name = "tapeage"
End With
End With

End Sub

thank you



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6,582
Default need help in my code on generating chart with dynamic range

1. Left out a "." Change

With ws
iRow = .Range("A" & Rows.Count).End(xlUp).Row


to

With ws
iRow = .Range("A" & .Rows.Count).End(xlUp).Row


2. Set Source Data assumes the range includes X values, Y values, and series
names of all series. You might be better off applying these directly to the
series. From http://peltiertech.com/Excel/ChartsH...ChartVBA.html:

Sub AddNewSeries()
With ActiveChart.SeriesCollection.NewSeries
.Name = ActiveSheet.Range("G3")
.Values = ActiveSheet.Range("G4:G14")
.XValues = ActiveSheet.Range("A4:A14")
End With
End Sub
or in your caseSub AddNewSeries()
With ActiveChart.SeriesCollection.NewSeries
.Name = ActiveSheet.Range("C1") ' guessing
.Values = ActiveSheet.Range("result")
.XValues = ActiveSheet.Range("names")
End With
End Sub
or
Sub AddNewSeries()
With ActiveChart.SeriesCollection.NewSeries
.Name = ActiveSheet.Range("C1") ' guessing
.Values = rng1
.XValues = rng
End With
End Sub


- Jon
-------
Jon Peltier, Microsoft Excel MVP
Tutorials and Custom Solutions
Peltier Technical Services, Inc. - http://PeltierTech.com
_______


"kiwis" wrote in message
ups.com...
Hi

I have some trouble with my code such that the source range will be
dynamic
Hopping that someone can enlighten my code, i have tried to debug but
can't get it to work.

Sub tapeagechart()

Dim ws As Worksheet
Dim rng As Range, rng1 As Range
Dim iRow As Long

Set ws = Worksheets("Sheet2")

'find last row
With ws
iRow = .Range("A" & Rows.Count).End(xlUp).Row
Set rng = .Range("A18:A" & iRow)
rng.Name = "names"
End With

Set rng1 = ws.Range("C18:C" & iRow)
rng1.Name = "result"


Charts.Add
ActiveChart.ChartType = xlLineMarkers
ActiveChart.SetSourceData Source:=Sheets("Sheet2").Range(?????) _
PlotBy:=xlColumns

i am having trouble in this line, i not sure what should i put
in ?????,
i tried putting the range name Range("names" ,"result") but it failed
this range will change according to my data

or i should use serial instead of setsourcedata source?


ActiveChart.Location Whe=xlLocationAsObject, Name:="Sheet2"

With ActiveChart
.HasTitle = True
.ChartTitle.Characters.Text = "Chart of Tape Age Summary"
.Axes(xlCategory).TickLabels.Orientation = xlUpward
With .Parent
.Top = Range("F18").Top
.Left = Range("F18").Left
.Name = "tapeage"
End With
End With

End Sub


thank you



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 24
Default need help in my code on generating chart with dynamic range

Thank you Jon,

i change a bit of your provided code & get it to work properly.

Thank you everyone who replied.


On May 30, 8:04 pm, "Jon Peltier"
wrote:
1. Left out a "." Change

With ws
iRow = .Range("A" & Rows.Count).End(xlUp).Row


to

With ws
iRow = .Range("A" & .Rows.Count).End(xlUp).Row


2. Set Source Data assumes the range includes X values, Y values, and series
names of all series. You might be better off applying these directly to the
series. Fromhttp://peltiertech.com/Excel/ChartsHowTo/QuickChartVBA.html:

Sub AddNewSeries()
With ActiveChart.SeriesCollection.NewSeries
.Name = ActiveSheet.Range("G3")
.Values = ActiveSheet.Range("G4:G14")
.XValues = ActiveSheet.Range("A4:A14")
End With
End Sub
or in your caseSub AddNewSeries()
With ActiveChart.SeriesCollection.NewSeries
.Name = ActiveSheet.Range("C1") ' guessing
.Values = ActiveSheet.Range("result")
.XValues = ActiveSheet.Range("names")
End With
End Sub
or
Sub AddNewSeries()
With ActiveChart.SeriesCollection.NewSeries
.Name = ActiveSheet.Range("C1") ' guessing
.Values = rng1
.XValues = rng
End With
End Sub

- Jon
-------
Jon Peltier, Microsoft Excel MVP
Tutorials and Custom Solutions
Peltier Technical Services, Inc. -http://PeltierTech.com
_______

"kiwis" wrote in message

ups.com...



Hi


I have some trouble with my code such that the source range will be
dynamic
Hopping that someone can enlighten my code, i have tried to debug but
can't get it to work.


Sub tapeagechart()


Dim ws As Worksheet
Dim rng As Range, rng1 As Range
Dim iRow As Long


Set ws = Worksheets("Sheet2")


'find last row
With ws
iRow = .Range("A" & Rows.Count).End(xlUp).Row
Set rng = .Range("A18:A" & iRow)
rng.Name = "names"
End With


Set rng1 = ws.Range("C18:C" & iRow)
rng1.Name = "result"


Charts.Add
ActiveChart.ChartType = xlLineMarkers
ActiveChart.SetSourceData Source:=Sheets("Sheet2").Range(?????) _
PlotBy:=xlColumns


i am having trouble in this line, i not sure what should i put
in ?????,
i tried putting the range name Range("names" ,"result") but it failed
this range will change according to my data


or i should use serial instead of setsourcedata source?


ActiveChart.Location Whe=xlLocationAsObject, Name:="Sheet2"


With ActiveChart
.HasTitle = True
.ChartTitle.Characters.Text = "Chart of Tape Age Summary"
.Axes(xlCategory).TickLabels.Orientation = xlUpward
With .Parent
.Top = Range("F18").Top
.Left = Range("F18").Left
.Name = "tapeage"
End With
End With


End Sub


thank you- Hide quoted text -


- Show quoted text -



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
Chart empty with new data in the dynamic range chart. Feejo Excel Discussion (Misc queries) 16 January 3rd 08 10:03 PM
TIP: Dynamic chart selection without code Dermot Charts and Charting in Excel 0 August 11th 06 08:23 AM
Dynamic Chart Via Code cherman Excel Programming 3 March 18th 06 12:25 AM
Create a dynamic chart with code [email protected] Excel Programming 1 July 2nd 05 05:51 PM
Dynamic Chart Range and Chart Update ExcelMonkey[_154_] Excel Programming 1 July 6th 04 08:26 PM


All times are GMT +1. The time now is 11:20 AM.

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"