VBA Chart code question for dynamic data

squeekee35

New Member
Joined
Nov 30, 2009
Messages
5
This site moves so fast and there is so much information on it. I can't find what i am looking for in past posts....i really hope some one can help me.

I created a VBA to chart data....a simple one (shown below my question)....

my question is how can i get the VBA to chart variable data...meaning one day i have 25 points on my graph and the next day i have 30 and maybe the day after that i only have 20. I can't seem to figure out how to change the R25 to be a varialbe number. any help would be appreciated
thankyou
angel

Charts.Add
ActiveChart.ChartType = xlXYScatterSmooth
ActiveChart.SetSourceData Source:=Sheets("Sheet1").Range("A1")
ActiveChart.SeriesCollection.NewSeries
ActiveChart.SeriesCollection(1).XValues = "=Sheet1!R1C1:R25C1"
ActiveChart.SeriesCollection(1).Values = "=Sheet1!R1C2:R25C2"
ActiveChart.SeriesCollection(1).Name = "=""Chart One"""
ActiveChart.Location Where:=xlLocationAsObject, Name:="Sheet1"
With ActiveChart
.HasTitle = True
.ChartTitle.Characters.Text = "Chart One"
.Axes(xlCategory, xlPrimary).HasTitle = True
.Axes(xlCategory, xlPrimary).AxisTitle.Characters.Text = _
"These are the x values"
.Axes(xlValue, xlPrimary).HasTitle = True
.Axes(xlValue, xlPrimary).AxisTitle.Characters.Text = _
"These are the y values"
End With
 

Excel Facts

Does the VLOOKUP table have to be sorted?
No! when you are using an exact match, the VLOOKUP table can be in any order. Best-selling items at the top is actually the best.
Here. This is the simple way.

Sub UsedRange_Example_Row() 'Untested
Dim A As Integer
Dim LastRow As Long
With ActiveSheet.UsedRange
LastRow = .Rows(.Rows.Count).Row
End With
A = LastRow
Charts.Add
ActiveChart.ChartType = xlXYScatterSmooth
ActiveChart.SetSourceData Source:=Sheets("Sheet1").Range("A1")
ActiveChart.SeriesCollection.NewSeries
ActiveChart.SeriesCollection(1).XValues = "=Sheet1!R1C1:R" & A & "C1"
ActiveChart.SeriesCollection(1).Values = "=Sheet1!R1C2:R" & A & "C2"
ActiveChart.SeriesCollection(1).Name = "=""Chart One"""
ActiveChart.Location Where:=xlLocationAsObject, Name:="Sheet1"
With ActiveChart
.HasTitle = True
.ChartTitle.Characters.Text = "Chart One"
.Axes(xlCategory, xlPrimary).HasTitle = True
.Axes(xlCategory, xlPrimary).AxisTitle.Characters.Text = _
"These are the x values"
.Axes(xlValue, xlPrimary).HasTitle = True
.Axes(xlValue, xlPrimary).AxisTitle.Characters.Text = _
"These are the y values"
End With
End Sub
 
Upvote 0
Thanx---

This worked out well but i had to change...

Lastrow= .rows(.rows.count).row

to

lastrow= activecell.end(xlDown)

thankyou thankyou thankyou
:)
angel
 
Upvote 0

Forum statistics

Threads
1,225,637
Messages
6,186,135
Members
453,340
Latest member
Stu61

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top