How to Fill Missing Excel Values with Linear Interpolation using VBA
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.

- 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.
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.
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.
Press Alt + F11 to open the Visual Basic for Applications (VBA) editor in Excel or WPS Spreadsheet.
Click 'Insert' from the top menu, then select 'Module' to create a new blank script window.
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.
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'.

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. Enable Developer Tools: Open your document in WPS Spreadsheet, navigate to the 'Options' menu, and ensure the 'Developer' tab is enabled.
- 2. Access the VBA Editor: Click on the 'Developer' tab and select 'Visual Basic Editor' (or press Alt + F11).
- 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.

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.




