I'm trying to create a macro for every time a data is inserted in the last line of Excel the chart automatically updates the selected range to include all the data present in the sheet but when the program executes an error occurs, can someone help me?
Code:
Public Sub Chart_Update()
Dim k As Long
k = Cells(Rows.Count, "B").End(xlUp).Row
Range("B2:B" & k & ",E2:E" & k & ",I2:I" & k & ",K2:K" & k).Select
ActiveChart.SetSourceData Source:=Range("AC_Offset_Registers!B2:B" & k & ",E2:E" & k & ",I2:I" & k & ", K2:K" & k)
ActiveWorkbook.Close SaveChanges:=True
End Sub
Error: