Combining Two Ranges

  • Thread starter Thread starter SoCalExcel
  • Start date Start date
S

SoCalExcel

I'm writing code to update a command very similar to

ActiveChart.SetSourceData Source:=Sheets("Graph
Data").Range("A1:A21,G1:M21"), PlotBy:=xlRows

except I need to do it using the 'Cells()' format. For
example, instead of using

Range("A1:A21,G1:M21")

since I'm using variables to reference the range, I
believe I need to use the 'Cells()' format instead of
the "A1:.." format. My attempts have looked something
like:

Range((Cells(1, 1), Cells(21, 1), (Cells(1, 7), Cells(10,
7))

This isn't working. Any help is greatly appreciated.

Thanks.
 
I've updated the code to read:

ActiveChart.SetSourceData Source:=Sheets("Graph
Data").Union(Range(Cells(1, 1), Cells(PriceBandCounter,
1)), Range(Cells(1, 7), Cells(PriceBandCounter, 7))),
PlotBy:=xlRows

This is returning a Run Time Error 438, Object doesn't
support this property or method...
 
Dim rng as Range
PriceBandCounter = 20

with Worksheets("Graph Data")
set rng = Union(.Range(.Cells(1, 1), .Cells(PriceBandCounter,1)), _
.Range(.Cells(1, 7), .Cells(PriceBandCounter, 7)))
End With

ActiveChart.SetSourceData Source:=rng, _
PlotBy:=xlRows
 
-----Original Message-----
Dim rng as Range
PriceBandCounter = 20

with Worksheets("Graph Data")
set rng = Union(.Range(.Cells(1, 1), .Cells (PriceBandCounter,1)), _
.Range(.Cells(1, 7), .Cells(PriceBandCounter, 7)))
End With

ActiveChart.SetSourceData Source:=rng, _
PlotBy:=xlRows

--
Regards,
Tom Ogilvy




.
 
Back
Top