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.