Force Excel to Include Empty XML Data Elements When Exporting
Question details
The user needs a method to force Excel to include XML tags for blank cells when exporting an XML data file, as the default behavior causes issues with target database systems.
- Product
- Microsoft Excel
- Device & OS
- not provided
- Scenario
- Exporting mapped XML data from a spreadsheet to import into another database system that requires all XML fields to be present.
- Observed behavior
- Excel automatically omits XML elements entirely for cells that are completely blank, resulting in missing tags rather than empty XML tags.
Before running any VBA macros, ensure you have enabled the Developer tab in your spreadsheet software and saved a backup copy of your workbook, as macro actions cannot be easily undone.
Use a VBA Macro to Fill Blank Cells with a Space Character
Since Excel automatically drops empty XML tags, you can use a VBA macro to insert a single space character into blank cells. This forces the software to export the XML element, ensuring database compatibility.
Excel's native XML export functionality is designed to skip elements for completely empty cells to minimize the file size. Unfortunately, there is no built-in checkbox to change this behavior.
To bypass this limitation, we can trick the system by filling empty cells with a single space character. After exporting, the receiving database system will typically read the space as a valid, albeit empty-looking, string or trim it entirely during import.
Press Alt + F11 on your keyboard to open the Visual Basic for Applications (VBA) editor.
In the top menu, click Insert and select Module to create a new blank script window.
Write a simple script that targets your specific data range, looping through each cell. Use an IF statement to check if the cell is empty (""), and if so, change its value to a single space (" ").
Press F5 or click the Run button to execute the macro. This will instantly populate all blank cells within your mapped XML columns.
Navigate to the Developer tab on your ribbon, click Export in the XML group, and save your newly populated XML file.
Handle Complex Spreadsheets Seamlessly with WPS Office
If you frequently deal with complex macros, data exports, or extensive spreadsheet management, WPS Office offers a lightweight, highly compatible alternative to Microsoft Office. It supports standard Excel formats and developer tools without the hefty subscription fees.
- 1. Download WPS Office: Visit the official WPS website to download and install the free software suite.
- 2. Open Your Excel File: Launch WPS Spreadsheet and open your existing .xlsx or .xlsm file containing the XML data mapping.
- 3. Run Macros: Enable developer tools from the settings to seamlessly run your existing VBA scripts and export your data.

Frequently Asked Questions
Why does Excel drop XML tags for empty cells?
Excel's default behavior is strictly designed to optimize the exported XML file size by omitting tags for cells that contain no data. Microsoft has not provided a native setting to toggle this behavior off.
Can I use a formula instead of a VBA macro to add spaces?
Yes. If you prefer not to use VBA, you can create a helper column using an IF formula (e.g., =IF(A2="", " ", A2)). You would then map your XML schema elements to this new helper column instead of the original raw data.
Will the space character cause issues in my receiving database?
It largely depends on the target database system. Most modern database import tools automatically trim trailing spaces, meaning the single space will be ingested as a true null or empty field. However, you should run a test import to verify it does not trigger validation errors.
How do I export an XML file after fixing the blank cells?
Once the blank cells are filled with a space, go to the Developer tab on the Excel ribbon, click 'Export' in the XML section, select your save destination, and click 'Export'.




