How to extract data from chart or graph in Excel?

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
1. You need to create a new worksheet and rename it as ChartData. See screenshot:
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:
You can then see the data extracted to the ChartData sheet.
Tip:
1. You can format the cells as you need.
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. Kutools for Excel - Supercharge Excel with over 300 essential tools. Enjoy permanently free AI features! Get It Now |
Best Office Productivity Tools
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!