I can't update the excel chart

KhallP

Board Regular
Joined
Mar 30, 2021
Messages
157
Office Version
  1. 2016
Platform
  1. Windows
I'm trying to update a chart every time a record is inserted in the last line of Excel, so I created a variable "k", the problem is that when I run the program I get an error that I can't solve, can someone help me?


Code:

VBA Code:
Public Sub Chart_Update()

Dim k As Long

k = Cells(Rows.Count, "B").End(xlUp).Row

Error at range!
--------------------------------------------------------------
Range("B2:B" & k, "E2:E" & k, "I2:I" & k, "J2:J" & k, "K2:K" & k).Select
----------------------------------------------------------------
ActiveChart.SetSourceData Source:=Range( _
"AC_Offset_Registers!$B$2:$B$&k,AC_Offset_Registers!$E$2:$E$&k,AC_Offset_Registers!$I$2:$I$&k,AC_Offset_Registers!$J$2:$J$&k,AC_Offset_Registers!$K$2:$K$&k" _
)
End Sub




Error:

capturar.JPG




Values i need to insert:

capturar.JPG




Chart:
capturar.JPG

Chart doens´t update the last row inserted value:

capturar.JPG
 

Attachments

  • capturar.JPG
    capturar.JPG
    22.6 KB · Views: 9

Excel Facts

Pivot Table Drill Down
Double-click any number in a pivot table to create a new report showing all detail rows that make up that number
I found out how to solve the problem but I still have problems on the segunite line due to the syntax (I don't know how to do it), I need help!

VBA 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:K" & k & ",J2:J" & k & "K2:K & k")

'What do I need to put here?
-------------------------
ActiveChart.SetSourceData Source:=Range( _
"AC_Offset_Registers!$B$2:$B$&k,AC_Offset_Registers!$E$2:$E$&k,AC_Offset_Registers!$I$2:$I$&k,AC_Offset_Registers!$J$2:$J$&k,AC_Offset_Registers!$K$2:$K$&k" _
)
-------------------
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,898
Messages
6,175,272
Members
452,628
Latest member
dd2

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top