Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default Chart source data

Hey

Can anyone help me to make a macro which will allow me to add sources by
activating a cell. I have the sources for the y axis. On the x-axis i would
like to update by clicking on a specific cell.

E.g
If i add something to a cell in column B (say B1), the source data in the
chart will automatically be updated to add content in column A (A1).

This is what I have tried, but i just get an error message saying compile
error: Expected: Then or GoTo

Sub AddSourceData()
ActiveSheet.Shapes.AddChart.Select
ActiveChart.SetSourceData Source:=Range("'Sheet2'!$B$10:$G$110")
ActiveChart.ChartType = xlLineMarkers
ActiveChart.SeriesCollection.NewSeries
ActiveChart.SeriesCollection(1).Values = "='Sheet2'!$U$11:$U$110"
ActiveChart.SeriesCollection(1).XValues = "='Sheet2'!$B$11"
If ActiveCell.Activate.Then XValues = Offset (0, -1).Range "B11"

End Sub

Thanks in advance

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,298
Default Chart source data

that last IF is wrong - delete it, you aren't using it. syntax is very bad
and I can see what it does


"Anders J." wrote:

Hey

Can anyone help me to make a macro which will allow me to add sources by
activating a cell. I have the sources for the y axis. On the x-axis i would
like to update by clicking on a specific cell.

E.g
If i add something to a cell in column B (say B1), the source data in the
chart will automatically be updated to add content in column A (A1).

This is what I have tried, but i just get an error message saying compile
error: Expected: Then or GoTo

Sub AddSourceData()
ActiveSheet.Shapes.AddChart.Select
ActiveChart.SetSourceData Source:=Range("'Sheet2'!$B$10:$G$110")
ActiveChart.ChartType = xlLineMarkers
ActiveChart.SeriesCollection.NewSeries
ActiveChart.SeriesCollection(1).Values = "='Sheet2'!$U$11:$U$110"
ActiveChart.SeriesCollection(1).XValues = "='Sheet2'!$B$11"
If ActiveCell.Activate.Then XValues = Offset (0, -1).Range "B11"

End Sub

Thanks in advance

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default Chart source data

Thanks

Do you have any suggestions on how I can change it for it to work? I tried
it without the IF and it still not working!

"Patrick Molloy" wrote:

that last IF is wrong - delete it, you aren't using it. syntax is very bad
and I can see what it does


"Anders J." wrote:

Hey

Can anyone help me to make a macro which will allow me to add sources by
activating a cell. I have the sources for the y axis. On the x-axis i would
like to update by clicking on a specific cell.

E.g
If i add something to a cell in column B (say B1), the source data in the
chart will automatically be updated to add content in column A (A1).

This is what I have tried, but i just get an error message saying compile
error: Expected: Then or GoTo

Sub AddSourceData()
ActiveSheet.Shapes.AddChart.Select
ActiveChart.SetSourceData Source:=Range("'Sheet2'!$B$10:$G$110")
ActiveChart.ChartType = xlLineMarkers
ActiveChart.SeriesCollection.NewSeries
ActiveChart.SeriesCollection(1).Values = "='Sheet2'!$U$11:$U$110"
ActiveChart.SeriesCollection(1).XValues = "='Sheet2'!$B$11"
If ActiveCell.Activate.Then XValues = Offset (0, -1).Range "B11"

End Sub

Thanks in advance

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,298
Default Chart source data

this worked for me:

Sub AddSourceData()
Dim ch As Chart
Dim sr As Series

Set ch = Charts.Add

With ch
.SetSourceData Source:=Range("'Sheet2'!$B$10:$G$110")
.ChartType = xlLineMarkers
Set sr = .SeriesCollection.NewSeries
End With

With sr
.Values = Worksheets("sheet2").Range("U11:U110")
.XValues = Worksheets("sheet2").Range("B11")
End With

End Sub


"Anders J." wrote:

Thanks

Do you have any suggestions on how I can change it for it to work? I tried
it without the IF and it still not working!

"Patrick Molloy" wrote:

that last IF is wrong - delete it, you aren't using it. syntax is very bad
and I can see what it does


"Anders J." wrote:

Hey

Can anyone help me to make a macro which will allow me to add sources by
activating a cell. I have the sources for the y axis. On the x-axis i would
like to update by clicking on a specific cell.

E.g
If i add something to a cell in column B (say B1), the source data in the
chart will automatically be updated to add content in column A (A1).

This is what I have tried, but i just get an error message saying compile
error: Expected: Then or GoTo

Sub AddSourceData()
ActiveSheet.Shapes.AddChart.Select
ActiveChart.SetSourceData Source:=Range("'Sheet2'!$B$10:$G$110")
ActiveChart.ChartType = xlLineMarkers
ActiveChart.SeriesCollection.NewSeries
ActiveChart.SeriesCollection(1).Values = "='Sheet2'!$U$11:$U$110"
ActiveChart.SeriesCollection(1).XValues = "='Sheet2'!$B$11"
If ActiveCell.Activate.Then XValues = Offset (0, -1).Range "B11"

End Sub

Thanks in advance

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
Include info from data source in data table but not in chart UHSH Admin Charts and Charting in Excel 1 February 26th 09 05:04 AM
pie chart & column chart w/same source data martymi Charts and Charting in Excel 2 May 1st 07 04:25 PM
Use detailed data in one worksheet to create summary data as chart source rdemyan Charts and Charting in Excel 0 January 23rd 07 02:18 PM
How do you link chart source data when you copy the chart? mamagirl Charts and Charting in Excel 1 December 8th 06 02:40 AM
Update a chart immediately after inputting data into data source MELMEL Charts and Charting in Excel 1 December 1st 05 09:34 PM


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