1

I am guessing this is a stupid logic/formatting issue, but I am pulling my hair out.

I am creating a chart in Excel, programmatically, using VBA. The user selects a range and this is passed on as a variable to setsoucedata. I performed this while recording a macro but I need this to be applicable to any user with any range, hence, variables and dynamic.

The macro shows the following, which works:

ActiveChart.SetSourceData Source:=Range("$C$36:$C$50,$E$36:$E$50,$K$36:$M$50")

My code to try and automate this is:

Dim rngTaskList As Range
Dim rngDateList As Range
Dim rngHiddenTable As Range

Set rngTaskList = Application.InputBox(Prompt:="Please select the task list of the project.", Title:="SPECIFY CELLS", Type:=8)
Set rngDateList = rngTaskList.Offset(0, 2)
Set rngHiddenTable = rngTaskList.Offset(0, 8)
ActiveSheet.Shapes.AddChart2(297, xlBarStacked).Select
ActiveChart.SetSourceData Source:=Range(rngTaskList, rngDateList, rngHiddenTable)

I keep getting a compile error: Wrong number of arguments or invalid property assignment.

I have tried about a dozen permutations, Unions, strings, to get this to work but I am sure there is something simple I am missing that should get this working. I know I can put the offsets within the Source but I broke it out to make it easier for me to understand and give my bloodshot eyes a break.

Anyone out there make any sense of this?

Thanks in advance.

1
  • 1
    Scott, you da man! Thank you, that fixed it. Commented Jul 10 at 18:09

2 Answers 2

2

Concatenate the addresses:

ActiveChart.SetSourceData Source:=Range(rngTaskList.address(0,0) & "," &rngDateList.address(0,0) & "," & rngHiddenTable.address(0,0))

Otherwise you are trying to pass 3 criteria to range which will not accept that.

Sign up to request clarification or add additional context in comments.

Comments

1

Late to the party, but this also fixes it:

ActiveChart.SetSourceData Source:=Union(rngTaskList, rngDateList, rngHiddenTable)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.