Skip to main content

How to extract data from chart or graph in Excel?

Author: Sun Last Modified: 2024-12-02
A screenshot of a chart in Excel without the original data

Charts in Excel are widely used to visualize data and trends more effectively. However, there may be situations where you only have a chart without access to its original data, as shown in the example below. In such cases, extracting the data from the chart can be essential. This tutorial provides a step-by-step guide to retrieving data from a chart or graph in Excel using VBA code.

Extract data from chart with VBA


arrow blue right bubble Extract data from chart with VBA

1. You need to create a new worksheet and rename it as ChartData. See screenshot:

A screenshot of the ChartData worksheet being created in Excel

2. Select the chart from which you want to extract data. Press Alt + F11 keys simultaneously to open the Microsoft Visual Basic for Applications window.

3. Click Insert > Module, then paste the below VBA code into the Module window.

Sub GetChartValues()
    'Updateby20220510
    Dim xNum As Integer
    Dim xSeries As Object
    On Error Resume Next
    xCount = 2
    xNum = UBound(Application.ActiveChart.SeriesCollection(1).Values)
    Application.Worksheets("ChartData").Cells(1, 1) = "X Values"
    With Application.Worksheets("ChartData")
        .Range(.Cells(2, 1), _
        .Cells(xNum + 1, 1)) = _
        Application.Transpose(ActiveChart.SeriesCollection(1).XValues)
    End With
    For Each xSeries In Application.ActiveChart.SeriesCollection
        Application.Worksheets("ChartData").Cells(1, xCount) = xSeries.Name
        With Application.Worksheets("ChartData")
            .Range(.Cells(2, xCount), _
            .Cells(xNum + 1, xCount)) = _
            Application.WorksheetFunction.Transpose(xSeries.Values)
        End With
        xCount = xCount + 1
    Next
End Sub

4. Then click Run button to run the VBA. See screenshot:

A screenshot of running VBA code in the Microsoft Visual Basic for Applications window

You can then see the data extracted to the ChartData sheet.
A screenshot of data extracted into the ChartData worksheet

Tip:

1. You can format the cells as you need.

A screenshot of data cells in the ChartData worksheet to be formatted

2. By default, the data of the selected chart is extracted starting from the first cell of the ChartData sheet.


Tip: If you frequently work with complex charts in Excel, recreating them each time can be tedious. With the Auto Text tool of Kutools for Excel, you can simplify this process. Create the charts once, add them to the AutoText pane, and reuse them anytime and anywhere. You only need to update the references to fit your specific needs.

A GIF demonstrating the AutoText tool in Kutools for Excel for reusing charts

Kutools for Excel - Supercharge Excel with over 300 essential tools. Enjoy permanently free AI features! Get It Now

Best Office Productivity Tools

🤖 Kutools AI Aide: Revolutionize data analysis based on: Intelligent Execution   |  Generate Code  |  Create Custom Formulas  |  Analyze Data and Generate Charts  |  Invoke Kutools Functions…
Popular Features: Find, Highlight or Identify Duplicates   |  Delete Blank Rows   |  Combine Columns or Cells without Losing Data   |   Round without Formula ...
Super Lookup: Multiple Criteria VLookup    Multiple Value VLookup  |   VLookup Across Multiple Sheets   |   Fuzzy Lookup ....
Advanced Drop-down List: Quickly Create Drop Down List   |  Dependent Drop Down List   |  Multi-select Drop Down List ....
Column Manager: Add a Specific Number of Columns  |  Move Columns  |  Toggle Visibility Status of Hidden Columns  |  Compare Ranges & Columns ...
Featured Features: Grid Focus   |  Design View   |   Big Formula Bar    Workbook & Sheet Manager   |  Resource Library (Auto Text)   |  Date Picker   |  Combine Worksheets   |  Encrypt/Decrypt Cells    Send Emails by List   |  Super Filter   |   Special Filter (filter bold/italic/strikethrough...) ...
Top 15 Toolsets12 Text Tools (Add Text, Remove Characters, ...)   |   50+ Chart Types (Gantt Chart, ...)   |   40+ Practical Formulas (Calculate age based on birthday, ...)   |   19 Insertion Tools (Insert QR Code, Insert Picture from Path, ...)   |   12 Conversion Tools (Numbers to Words, Currency Conversion, ...)   |   7 Merge & Split Tools (Advanced Combine Rows, Split Cells, ...)   |   ... and more

Supercharge Your Excel Skills with Kutools for Excel, and Experience Efficiency Like Never Before. Kutools for Excel Offers Over 300 Advanced Features to Boost Productivity and Save Time.  Click Here to Get The Feature You Need The Most...


Office Tab Brings Tabbed interface to Office, and Make Your Work Much Easier

  • Enable tabbed editing and reading in Word, Excel, PowerPoint, Publisher, Access, Visio and Project.
  • Open and create multiple documents in new tabs of the same window, rather than in new windows.
  • Increases your productivity by 50%, and reduces hundreds of mouse clicks for you every day!