How to Test Whether an Excel Cell Contains a Valid Single-Cell Address
Question details
The user needs a formula or custom function to verify if text represents a valid single-cell address (like C45 or $DB$3) while rejecting ranges, invalid text, and blanks.

- Product
- Excel
- Device & OS
- not provided
- Scenario
- Validating user input or string data to ensure it accurately points to exactly one cell without evaluating references across closed workbooks.
- Observed behavior
- Standard formulas using the INDIRECT function fail or return errors when the cell address cannot be resolved in the current active workbook.
Ensure that the Developer tab is enabled in your spreadsheet's ribbon so you can access the VBA Editor to create a custom User-Defined Function (UDF).
Use a Custom VBA Function (Recommended)
Create a custom VBA function to evaluate the text string directly. This method bypasses INDIRECT limitations and accurately rejects ranges by scanning for colons.
By writing a simple VBA macro, you can assign the string to a Range object in the background. If the assignment fails or if the text contains a colon, the function recognizes it as invalid or a multi-cell range and returns False.
Press the ALT + F11 keys on your keyboard to open the Visual Basic for Applications (VBA) editor.
In the VBA editor, go to the top menu and click Insert, then select Module to create a blank workspace.
Copy and paste the following VBA code into the module window: Function IsSingleCellAddress(s As String) As Boolean Dim rng As Range If InStr(s, ":") = 0 Then On Error Resume Next Set rng = Range(s) IsSingleCellAddress = Not rng Is Nothing End If End Function
Close the VBA editor and return to your worksheet. Select a blank cell and type the formula =IsSingleCellAddress(A1) to test the string value contained in cell A1.
Use the INDIRECT Formula (For Local References Only)
If you only need to validate addresses within the active, open workbook, a complex formula using INDIRECT can be used as a workaround.
Run Custom VBA Functions Seamlessly with WPS Spreadsheet
WPS Office Spreadsheet provides comprehensive support for VBA and macros, allowing you to easily build, test, and run custom functions like the single-cell validation script without advanced configuration.
- 1. Enable the Developer Tab: Open WPS Spreadsheet, go to the settings to enable the Developer tab if it isn't already visible.
- 2. Access the VBA Editor: Click on 'VBA Editor' on the Developer ribbon to open the macro environment.
- 3. Create Your Custom Function: Insert a new Module, paste your VBA script, and immediately start using the custom formula in your spreadsheet cells.

Frequently Asked Questions
Why does the INDIRECT function return a #REF! error for a valid cell address?
The INDIRECT function requires the referenced workbook to be currently open in the same application instance. If the address points to an external workbook that is closed, the function cannot resolve the reference and will return a #REF! error.
How does the custom VBA function exclude multi-cell ranges?
The VBA code uses the InStr function to search the text string for a colon (:). Since multi-cell ranges (like A1:C5) always contain a colon, finding one immediately triggers the function to skip the range assignment and return False.
Will this VBA code recognize absolute cell references as valid?
Yes, the VBA Range(s) object assignment successfully recognizes and handles absolute references (e.g., $A$1), relative references (e.g., A1), and mixed references (e.g., $A1) as valid single-cell addresses.




