Logo 
Search:

MS Office Answers

Ask Question   UnAnswered
Home » Forum » MS Office       RSS Feeds
  Question Asked By: Ketan Dave   on Jan 18 In MS Office Category.

  
Question Answered By: Sean Grant   on Jan 18

It won't like the zero in
Set XTemp = Range("C1").Resize(x, 0)
because you can't have a selection zero columns wide I think.
Also is x properly defined somewhere? I suspect you mean to use
amtrows there?

The line
ActiveChart.SetSourceData Source:=Sheets("Sheet5").Range(XTemp),
PlotBy _ :=xlColumns

will confuse vba  as you've already defined XTemp as a range so
Range(Xtemp) may be a little dodgy.
Set the range to include sheet info as well:
Set XTemp = Sheets("Sheet5").Range("C1").Resize(amtrows, 1)

and change the SetSource line to:
ActiveChart.SetSourceData Source:=XTemp, PlotBy:=xlColumns

It also helps to be explicit about which sheet Range("A8") is on:
amtrows = Sheets("Sheet5").Range("A8").Value


Macro in full:

Dim amtrows As Long
Dim XTemp As Range
amtrows = Sheets("Sheet5").Range("A8").Value
Set XTemp = Sheets("Sheet5").Range("C1").Resize(amtrows, 1)
ActiveSheet.ChartObjects("Chart 2").Activate
ActiveChart.ChartArea.Select
ActiveChart.SetSourceData Source:=XTemp, PlotBy:=xlColumns
ActiveWindow.Visible = False

Share: 

 

This Question has 2 more answer(s). View Complete Question Thread

 
Didn't find what you were looking for? Find more on VBA Help With Chart Object Problem Or get search suggestion and latest updates.


Tagged: