Hello jieyi,
You have set the object variable "myrange" to the ranges in the Union and that's correct. The problem lies in how you are assigning the range to the chart. You are trying to reference your new range as a named ranged, which it isn't. See below in red...
Projects = CurrentSheet.Range("B16").End(xlUp).Row
Set myrange = Union(CurrentSheet.Range(Cells(5, 2), Cells(Projects, 2)), CurrentSheet.Range(Cells(5, 4), Cells(Projects, 4)), CurrentSheet.Range("B16"), CurrentSheet.Range("D16"))
With ActiveChart
.SetSourceData Source:=Range("myrange")
End With
The code should be as below...
Projects = CurrentSheet.Range("B16").End(xlUp).Row
Set myrange = Union(CurrentSheet.Range(Cells(5, 2), Cells(Projects, 2)), CurrentSheet.Range(Cells(5, 4), Cells(Projects, 4)), CurrentSheet.Range("B16"), CurrentSheet.Range("D16"))
With ActiveChart
.SetSourceData Source:=myrange
End With
Bookmarks