How to Fix SUMIFS Formula Displaying as Text via VBA in Excel
Question details
The user needs to correctly insert a SUMIFS formula referencing a network drive into a cell using VBA, ensuring it calculates properly rather than being formatted as text.

- Product
- Excel
- Device & OS
- not provided
- Scenario
- Using VBA to dynamically insert a SUMIFS formula into a specific cell that references another workbook on a network drive.
- Observed behavior
- The inserted formula begins with a leading apostrophe (e.g., '=SUMIFS) and is displayed as plain text in the cell instead of evaluating the result.
Ensure your Excel workbook is saved as a Macro-Enabled Workbook (.xlsm) and that you have enabled macros in the Trust Center before modifying your VBA scripts.
Remove the Leading Apostrophe in the VBA String
Correct the VBA code by removing the apostrophe before the equals sign to ensure the application evaluates the formula instead of treating it as text.
When writing VBA code to insert formulas, placing a single apostrophe (') directly before the equals sign forces the cell to treat the entry as text. Removing this character will restore standard formula calculation.
Press Alt + F11 on your keyboard to open the Visual Basic for Applications (VBA) editor.
In the Project Explorer panel on the left, double-click the module or worksheet containing your formula insertion script.
Find the line of code assigning the formula. Change it from Range("X12").Formula = "'=SUMIFS(...)" to Range("X12").Formula = "=SUMIFS(...)". Ensure the apostrophe following the opening quotation mark is completely deleted.
Press Ctrl + S to save the code. Return to your worksheet and run the macro again; the cell should now display the calculated result of the SUMIFS formula.

Write and Execute VBA Macros in WPS Spreadsheet
WPS Office provides robust support for macros and complex formulas like SUMIFS. You can seamlessly run your existing VBA scripts to automate tasks and manage network drive references without text-formatting errors.
- 1. Open Your Workbook in WPS: Launch WPS Office and open your Macro-Enabled Workbook (.xlsm).
- 2. Access the Developer Tab: Navigate to the 'Developer' tab on the main ribbon to access your macro and coding settings.
- 3. Edit the Macro Code: Click on 'Visual Basic' to open the code editor and modify your SUMIFS script, ensuring formulas are formatted without a leading apostrophe.
- 4. Execute the Script: Click the 'Run Macro' button to dynamically insert and calculate the SUMIFS formula seamlessly across your network references.

Frequently Asked Questions
Why do formulas entered via VBA sometimes show as text?
This typically happens if the target cell's format was pre-set to 'Text' before the macro executed, or if the VBA code intentionally or accidentally included a leading apostrophe before the formula's equals sign.
How do I insert VBA variables into a SUMIFS formula?
You can insert variables into your formula string using the ampersand (&) operator to concatenate the text. For example: Range("A1").Formula = "=SUMIFS(B:B, C:C, " & myVariable & ")".
Does WPS Office support Excel VBA scripts for formulas?
Yes, WPS Office fully supports VBA macros. You can open your Excel .xlsm files in WPS Spreadsheet and execute most standard VBA scripts, including those that manipulate ranges and insert complex formulas.




