Create an Excel Chart from the Current Data Region with VBA
Question details
Create an Excel chart from the data block containing the active cell rather than the fixed range captured by a recorded macro.

- Product
- Microsoft Excel
- Device & OS
- not provided
- Scenario
- A user selects a cell in a data block separated from other blocks by blank rows and runs a chart macro.
- Observed behavior
- The recorded macro continues to use its original data range instead of the currently selected data block.
Ensure the data block has no completely blank rows or columns within it and is separated from other data by blank rows or columns. Save the workbook as an Excel Macro-Enabled Workbook (.xlsm) if you want to retain the macro.
Use CurrentRegion to chart the active data block
Replace a recorded fixed range with the contiguous region surrounding the active cell.
ActiveCell.CurrentRegion returns the rectangular data region bounded by blank rows and columns. It includes headers when they are part of that region.
In Excel, open Developer > Visual Basic, then choose Insert > Module.
Paste this code into the module: Sub ChartCurrentRegion() Dim rng As Range Dim chartObj As ChartObject Set rng = ActiveCell.CurrentRegion Set chartObj = ActiveSheet.ChartObjects.Add( _ Left:=rng.Left + rng.Width + 20, Top:=rng.Top, _ Width:=360, Height:=240) chartObj.Chart.SetSourceData Source:=rng chartObj.Chart.ChartType = xlColumnClustered End Sub
Return to the worksheet and click any cell inside the block you want to chart.
Open Developer > Macros, select ChartCurrentRegion, and click Run. Excel creates a clustered column chart using the current region.

Create spreadsheet charts with WPS Office
WPS Office is a free, lightweight Office alternative with a familiar interface. Open compatible Excel files and create charts from selected data, making it easy to move everyday spreadsheet work to WPS. It does not fix Excel's VBA macro behavior.

Frequently Asked Questions
Why does my recorded macro keep charting the old range?
Macro recording can capture a fixed range address. In the VBA editor, replace that reference with ActiveCell.CurrentRegion so the chart uses the block containing the active cell.
Do I need to select the entire data block before running the macro?
No. Click one cell inside the desired block, then run the macro from Developer > Macros. CurrentRegion identifies the surrounding contiguous region.
Why is part of my data missing from the chart?
A completely blank row or column can end the current region. Check the worksheet for gaps within the intended data, remove them if appropriate, and run the macro again.
How do I keep the macro in my workbook?
Choose File > Save As and select Excel Macro-Enabled Workbook (.xlsm). When reopening the file, enable macros only if you trust the workbook.




