automated plotting in excel.. need help - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

automated plotting in excel.. need help

jdelkjdelk Posts: 14Member
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

Comments

  • PavlinIIPavlinII Posts: 404Member
    : 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?



    [blue][b][italic][size=4]P[/size]avlin [size=4]II[/italic][/size][/b][/blue]

    [purple]Don't take life too seriously anyway you won't escape alive from it![/purple]


Sign In or Register to comment.