How to Format VBA Numbers with Leading Zeros and Edit Table Formulas in WPS Office Spreadsheet
Question details
The user needs to format VBA-generated sequence numbers with consistent four-digit leading zeros and edit calculated-column formulas in an Excel table after rows are populated.
- Product
- WPS Office Spreadsheet
- Device & OS
- not provided
- Scenario
- The user is generating a file with VBA sequence numbers from data in an Excel table. The table uses calculated-column formulas that are not visible until the table has populated rows.
- Observed behavior
- The VBA-generated sequence numbers appear inconsistently as 001, 002, 0100, and 0101 instead of consistent four-digit values. The Excel table calculated-column formula is not visible until the table has populated rows.
Open the workbook in WPS Office Spreadsheet and enable macros so the VBA code can run. Confirm that the source data is in an Excel table and locate the calculated column you need to edit.
Use the VBA Format Function to Apply Consistent Four-Digit Leading Zeros
Use this when VBA-generated sequence numbers show inconsistent lengths because conditional zero-padding does not cover all values.
The Format function converts the numeric value to text with a fixed pattern. In this case, Format(D, "0000") always produces four characters, so 1 becomes 0001, 10 becomes 0010, and 100 becomes 0100.
In WPS Office Spreadsheet, press Alt+F11 to open the VBA editor and find the module containing the sequence number code.
Delete the If D < 10 Then ... Else ... End If block and enter array192(Z) = x.Offset(0, -1) & Format(D, "0000").
Switch back to WPS Office Spreadsheet and run the macro from the Macro dialog or with the assigned shortcut to regenerate the sequence numbers.
Edit an Excel Table Calculated-Column Formula After Populating Rows
Use this when a table calculated-column formula is not visible because the table has no populated rows, or when you need to replace the formula throughout the column.
Use WPS Office Spreadsheet to Format VBA Number Sequences and Edit Table Formulas
WPS Office Spreadsheet supports VBA macros and Excel table calculated columns. Use the Format(D, "0000") replacement directly in the VBA editor, then edit table formulas after adding data rows.
- 1. Open the workbook in WPS Office Spreadsheet: Launch WPS Office Spreadsheet and open the workbook that contains the VBA macro and Excel table.
- 2. Edit the VBA sequence number code: Press Alt+F11 to open the VBA editor, find the conditional zero-padding block, and replace it with array192(Z) = x.Offset(0, -1) & Format(D, "0000").
- 3. Run the macro: Return to the spreadsheet and run the macro from the Developer tab or Macro dialog to regenerate the sequence numbers.
- 4. Correct the table calculated-column formula: Add a populated data row, select the calculated column cell, enter the corrected formula in the formula bar, and confirm the calculated column overwrite.
- 5. Save as an Excel-compatible workbook: Go to Menu > Save As and choose the Excel .xlsx or macro-enabled format to keep the file compatible with Microsoft Excel.

Frequently Asked Questions
Why do my VBA sequence numbers lose leading zeros for values above 99?
Conditional code such as If D < 10 Then ... Else ... End If only adds zeros for specific ranges. Replace it with array192(Z) = x.Offset(0, -1) & Format(D, "0000") in the VBA editor to force four digits for all values.
How do I apply the Format function to multiple sequence numbers in VBA?
Open the VBA editor with Alt+F11, locate the sequence number generation block, and replace the conditional zero-padding logic with Format(D, "0000") so every value uses the same four-character pattern.
Why can’t I see an Excel table calculated-column formula?
An Excel table must have at least one populated data row before the calculated-column formula becomes visible. Add a value to a data row, then select the calculated column cell to view or edit the formula in the formula bar.
How do I edit a calculated-column formula after the table has rows?
Select the calculated column cell in a populated row, enter the corrected formula in the formula bar, press Enter, and confirm the overwrite prompt so the formula copies throughout the calculated column.
Can WPS Office open and run VBA macro workbooks created in Microsoft Excel?
Yes, WPS Office Spreadsheet can open Excel macro-enabled workbooks and run many VBA macros. Open the workbook in WPS Office Spreadsheet and enable macros if prompted.




