VBA & Macro Problems

How to Fill Missing Excel Values with Linear Interpolation using VBA

Huma Ashraf ChHuma Ashraf Ch Oct 29, 2026 869 views

Question details

The user needs to fill blank cells in a time series or data column by estimating values between existing data points using linear interpolation.

How to Fill Missing Excel Values with Linear Interpolation using VBA
Product
Excel / WPS Spreadsheet
Device & OS
not provided
Scenario
Estimating missing values in an irregular time series or data set.
Observed behavior
Excel lacks a built-in shortcut for linear interpolation, leaving users to manually calculate or find an automated solution to populate missing values.
Before you start

Ensure that the first and last cells in your selected data range contain actual numeric values, and back up your spreadsheet before running any new VBA macros.

Solution 1Recommended

Use a VBA Macro to Interpolate Missing Values

Since there is no built-in shortcut, applying a custom VBA macro is the most efficient way to calculate and fill missing values between populated cells.

This macro solution requires you to select a single-column range where the top and bottom cells are not empty. The macro will scan for blank cells and automatically calculate proportional values based on the surrounding populated data points.

1
Open the VBA Editor

Press Alt + F11 to open the Visual Basic for Applications (VBA) editor in Excel or WPS Spreadsheet.

2
Insert a New Module

Click 'Insert' from the top menu, then select 'Module' to create a new blank script window.

3
Write the Macro Code

Paste your linear interpolation macro code into the module window. Ensure the script is designed to loop through the selected range and apply the mathematical interpolation formula to empty cells.

4
Run the Macro

Close the VBA editor. Select your target single-column data range (ensuring the first and last cells have data), go to the 'Developer' tab, click 'Macros', choose your interpolation macro, and click 'Run'.

Use a VBA Macro to Interpolate Missing Values
Quick Access Shortcut: For frequent use, you can assign this newly created macro to a keyboard shortcut or add it as a button on your Quick Access Toolbar.
Efficient Data Analysis with WPS Office

Run VBA Macros Seamlessly in WPS Spreadsheet

WPS Spreadsheet provides robust support for VBA macros, allowing you to easily run linear interpolation scripts to fill missing values, just as you would in Microsoft Excel.

  1. 1. Enable Developer Tools: Open your document in WPS Spreadsheet, navigate to the 'Options' menu, and ensure the 'Developer' tab is enabled.
  2. 2. Access the VBA Editor: Click on the 'Developer' tab and select 'Visual Basic Editor' (or press Alt + F11).
  3. 3. Execute Your Macro: Insert a module, paste your interpolation code, highlight the data range in your sheet, and run the macro to instantly fill the missing values.
Full compatibility with Microsoft Excel macro-enabled (.xlsm) and standard (.xlsx) formats.Robust VBA support for automating complex data analysis tasks like interpolation.Lightweight software that loads large time-series datasets instantly.
microsoft office alternative - wps office

Frequently Asked Questions

What is linear interpolation in spreadsheets?

Linear interpolation is a method of estimating unknown values that fall between known values. In a spreadsheet, it's often used to fill gaps in an irregular time series by calculating a steady rate of change between two populated data points.

Why am I getting an error when running the interpolation macro?

Errors typically occur if the selected range spans multiple columns, or if the very first or last cell in your selection is empty. Ensure you select only a single column and that the boundary cells contain numeric values before running the script.

Does Excel have a built-in function for linear interpolation?

Excel does not have a single direct built-in function or shortcut specifically for linear interpolation, though you can use a combination of FORECAST or TREND functions manually. Using a VBA macro remains the most automated way to fill multiple gaps in a dataset.

Can I undo a VBA macro after running it?

No, actions performed by a VBA macro typically cannot be undone using the standard 'Undo' feature (Ctrl + Z). It is highly recommended to save a backup copy of your worksheet before running any macro that modifies data.