VBA & Macro Problems

Create an Excel Chart from the Current Data Region with VBA

John WilsonJohn Wilson Nov 27, 2026 869 views

Question details

Create an Excel chart from the data block containing the active cell rather than the fixed range captured by a recorded macro.

Create an Excel Chart from the Current Data Region with VBA
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.
Before you start

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.

Solution 1Recommended

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.

1
Open the VBA editor

In Excel, open Developer > Visual Basic, then choose Insert > Module.

2
Add the chart macro

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

3
Select the data block

Return to the worksheet and click any cell inside the block you want to chart.

4
Run the macro

Open Developer > Macros, select ChartCurrentRegion, and click Run. Excel creates a clustered column chart using the current region.

Use CurrentRegion to chart the active data block
Check the region boundaries: A completely blank row or column inside the intended data can split the region. Adjacent data without a blank separator can be included in the chart.
Free Microsoft Office alternative

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.

Create charts from selected spreadsheet dataCompatible with Microsoft Excel XLSX filesFamiliar spreadsheet interface for easier migrationFree and lightweight for everyday Office tasks
QA img-9

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.