Home > Mobile >  Macro selecting multiple column as source graph
Macro selecting multiple column as source graph

Time:06-15

I want to know how do I select multiple columns as source of graph using macro, I try below method :

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

The problem with above code is adding all columns between Column B and E. I want to to only add column B and E and nothing else.

CodePudding user response:

The Worksheet.Range property has to 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