Question : Using Range(Cells(r1,c1),Cells(r<wbr />2,c2)) instead of Range("A1:B2")

Hello,

This should be a simple one....

This statement works:
ActiveChart.SetSourceData Source:=Sheets("DATA").Range("C1:AP14"), _
        PlotBy:=xlColumns

but this one doesn't:
ActiveChart.SetSourceData Source:=Sheets("DATA").Range(Cells(1, 3), Cells(14, 42)), _
        PlotBy:=xlColumns

i tried setting a range and feeding it that - but that didn't work either.

I'd like to be able to set the plot area dynamically - any ideas?

Thanks

davsay

Answer : Using Range(Cells(r1,c1),Cells(r<wbr />2,c2)) instead of Range("A1:B2")

Hi davsay,

Strangely (stupidly, IMHO), only the first part of a two part Range statement ("Cells" statement in your case) is qualified by a preceeding sheet object ('Sheets("DATA")' in your case)

There are any number of ways to get around this, here are a couple different ways to do it:

 ActiveChart.SetSourceData Source:=Sheets("DATA").Range(Cells(1, 3), Sheets("DATA") _
  .Cells(14, 42)), PlotBy:=xlColumns
 
 ActiveChart.SetSourceData Source:=Range(Sheets("DATA").Cells(1, 3), Sheets("DATA") _
  .Cells(14, 42)), PlotBy:=xlColumns
 
 With Sheets("DATA")
  ActiveChart.SetSourceData Source:=Range(.Cells(1, 3), .Cells(14, 42)), PlotBy:=xlColumns
 End With

Matt
Random Solutions  
 
programming4us programming4us