Please Help With Chart Code

W

WayneK

Hi. I am using Excel 2003.

I used the macro recorder and modied some of the code in the hopes tha
the
VBA I wrote work work. Instead, it produces errors. I have a Char
object on
a Sheet that I wish to "feed" a range to chart. Since the number o
rows for the
needed range changes from time to time, I included a variable calle
amtrows.
Then I try to "assign" a range to variable XTemp. Then I try to fee
that XTemp
range into the Chart object.

My modified code errors at this line --

Set XTemp = Range("C1").Resize(x, 0)

And at this line as well --

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

Could you please review my code below and tell me what to change ?
would be most
grateful for your help.

WayneK

Dim amtrows As Long
Dim XTemp As Range

amtrows = Range("A8").Value

Set XTemp = Range("C1").Resize(x, 0)

ActiveSheet.ChartObjects("Chart 2").Activate
ActiveChart.ChartArea.Select
ActiveChart.SetSourceData Source:=Sheets("Sheet5").Range(XTemp), PlotB
_
:=xlColumns
ActiveWindow.Visible = Fals
 
P

Peter T

Hi Wayne,

Have a look at this line -

Set XTemp = Range("C1").Resize(x, 0)

Resize requires the row & column arguments each to be at least 1. Both yours
are 0, as you have not assigned a value to x.

You say "amtrows" is required but it's not used in your code.

Subject to setting XTemp to a cell range that works with your chart type the
rest of your code should work, but no need to select the chartarea.

Regards,
Peter T
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top