VBA

Moderators: PavlinII
Number of threads: 1673
Number of posts: 3078

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
automated plotting in excel.. need help Posted by jdelk on 1 Feb 2006 at 3:44 PM
Can someone help me understand why I can't use the folling code to autoplot in a file?

Range(Cells(2, 1), Cells(variable, 2)).Select

Charts.Add
ActiveChart.ChartType = xlXYScatter
ActiveChart.SetSourceData Source:=Sheets(sheetname).Range(Cells(2,_ 1), Cells(variable, 2)), PlotBy:=xlColumns

My code runs right thru the first Range selection without a problem but when I want to designate source data, it doesn't like it.

I need to do it this way because the files I am plotting are of variable rows. I use a counter to count down until there is no data in a row then the variable is the row number that all the plots need to go to.
I tried concatenating the variable number with the other method for range selection

Range("A2:B"&variable) type of thing but that doesn't work either.

Any ideas on what might be the problem or how I might use a variable in the range selection process???

Thanks

Report
Re: automated plotting in excel.. need help Posted by PavlinII on 14 Feb 2006 at 2:00 PM
: Can someone help me understand why I can't use the folling code to autoplot in a file?
:
: Range(Cells(2, 1), Cells(variable, 2)).Select
:
: Charts.Add
: ActiveChart.ChartType = xlXYScatter
: ActiveChart.SetSourceData Source:=Sheets(sheetname).Range(Cells(2,_ 1), Cells(variable, 2)), PlotBy:=xlColumns
:
: My code runs right thru the first Range selection without a problem but when I want to designate source data, it doesn't like it.
:
: I need to do it this way because the files I am plotting are of variable rows. I use a counter to count down until there is no data in a row then the variable is the row number that all the plots need to go to.
: I tried concatenating the variable number with the other method for range selection
:
: Range("A2:B"&variable) type of thing but that doesn't work either.
:
: Any ideas on what might be the problem or how I might use a variable in the range selection process???
:
: Thanks
:
:
Hi, I've tried your code and it works fine in my excel :(
And I've tried Range("A2:B" & variable) method and it also worked..
(I have Excel 10.3506 sp1)..
I just had to set Variable=5 and sheetname="sheet1"..
Be carefull, becouse when you use Range(Cells... and then Sheets(Sheetname).Cells, it can point to different places..
What error does it tell you, when you run your code?
Or no error is given and code just does not work?



Pavlin II[/size]

Don't take life too seriously anyway you won't escape alive from it!





 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.