Chart selection without reference to chart number

I want to select a random chart on a sheet in excel using VBA, without knowing the chart number, because the generated chart always changes in number. Can anyone help? Can I select a chart without reference to the chart number? I want to change the name of the chart of the active chart.

1 ActiveSheet.ChartObjects("Chart 409").Activate 2 ActiveSheet.Shapes("Chart 409").Name = "Chart 1" 3 ActiveSheet.ChartObjects("Chart 1").Activate 
+6
source share
1 answer

To select all charts or random ones, you can use the chart index.

 Sub getcharts() Dim ws As Worksheet Dim ch As ChartObject Set ws = ActiveSheet cnt = ws.ChartObjects.Count random_num = Application.WorksheetFunction.RandBetween(1, cnt) ws.ChartObjects(random_num).Name = "NAM" 'The Random chart For Each ch In ws.ChartObjects ch.Name = "Put the name of Chart here " 'Or Do anything with you all the charts here Next End Sub 
+1
source

Source: https://habr.com/ru/post/951540/


All Articles