Error selecting range with variable

Status
Not open for further replies.

KhallP

Board Regular
Joined
Mar 30, 2021
Messages
100
Office Version
  1. 2016
Platform
  1. Windows
Criei um código para que cada vez que um registo fosse inserido numa linha o programa detetasse a última linha com valores (atribuido á variável "k") e selecionasse um intervalo específico para que o gráfico atualizasse, mas um erro ocorre, alguem me podia ajudar?



VBA Code:
Public Sub Chart_Update()

Dim k As Long

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

Error
------------------------------------------------------------------
    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
 

Excel Facts

Copy a format multiple times
Select a formatted range. Double-click the Format Painter (left side of Home tab). You can paste formatting multiple times. Esc to stop

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
58,237
Office Version
  1. 365
Platform
  1. Windows
Duplicate to: I can´t range the cells interval

In future, please do not post the same question multiple times. Per Forum Rules (#12), posts of a duplicate nature will be locked or deleted.

In relation to your question here, I have closed this thread so please continue in the linked thread.
 
Status
Not open for further replies.

Watch MrExcel Video

Forum statistics

Threads
1,132,895
Messages
5,655,830
Members
418,242
Latest member
k3itall

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
Top