How to Always Keep a Chart in View When Scrolling in Excel?


When you are collecting the data and presenting it in a chart, it is very important to keep the chart still even when you are moving the data. Generally, in Excel, a chart is saved based on the cells, but we can make the chart float in the sheet even when we scroll the data.

This tutorial will help you understand how we can always keep a chart in view when scrolling in Excel. We will be using the concept of VBA code in order to make our result possible.

Always Keep a Chart in View When Scrolling

Here we will first insert VBA code into the sheet, then our task will be completed. Let us see a simple process to understand how we can always keep a chart in view when scrolling in Excel.

Step 1

Assume we have an excel sheet with data similar to the data shown in the image below.

Now to create the chart, select the data and click on "Insert," then select any chart you want to use. We will be selecting a line chart as shown in the below image.

Step 2

Now, right-click on the sheet name and select View Code from the menu to open the VBA application, enter the programme in the text box, save the VBA code, and close the VBA application using the code Alt + Q.

Program

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
'Update by nirmal
   Dim CPos As Double
   Application.ScreenUpdating = False
   CPos = ActiveWindow.ScrollRow * ActiveCell.RowHeight
   ActiveSheet.ChartObjects("nirmal").Activate
   ActiveSheet.Shapes("nirmal").Top = CPos
   ActiveWindow.Visible = False
   Application.ScreenUpdating = True
End Sub

Step 3

The chart will always follow the mouse click as we click on the data set. In the programme, Nirmal, which is used in lines 6 and 7, is the name of the chart, and this can only be used for one chart at a time.

Conclusion

In this tutorial, we used a simple example to demonstrate how we can always keep a chart in view when scrolling in Excel to highlight a particular set of data.

Updated on: 09-Jan-2023

796 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements