Selecting non-contiguous columns as graph source

Viewed 42

I want to select non-contiguous columns as source of graph, I tried:

ActiveChart.SetSourceData Source:=Sheets("Data").Range("B1:B2", "E1:E3"), _
  PlotBy:=xlColumns

The code is adding columns B to E. I want column B and column E.

1 Answers

The Worksheet.Range property has two parameters:

Name Required/Optional Data type Description
Cell1 Required Variant A String that is a range reference when one argument is used. Either a String that is a range reference or a Range object when two arguments are used.
Cell2 Optional Variant Either a String that is a range reference or a Range object. Cell2 defines another extremity of the range returned by the property.

Because Range("B1:B2", "E1:E3") is Range(a, b) that means range from a to b.

You probably meant Range("B1:B2,E1:E3") which means a non-continous range of B1:B2 and E1:E3.

Related