VBA & Macro Problems

How to Test Whether an Excel Cell Contains a Valid Single-Cell Address

Anum MushtaqAnum Mushtaq Nov 3, 2026 870 views

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.

How to Test Whether an Excel Cell Contains a Valid Single-Cell Address
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.
Before you start

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).

Solution 1Recommended

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.

1
Open the VBA Editor

Press the ALT + F11 keys on your keyboard to open the Visual Basic for Applications (VBA) editor.

2
Insert a New Module

In the VBA editor, go to the top menu and click Insert, then select Module to create a blank workspace.

3
Paste the Custom Function Code

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

4
Apply the Function in Your Worksheet

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.

Save as Macro-Enabled: Remember to save your workbook as a Macro-Enabled Workbook (.xlsm) to ensure the custom function works the next time you open the file.
Advanced Spreadsheet Features

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. 1. Enable the Developer Tab: Open WPS Spreadsheet, go to the settings to enable the Developer tab if it isn't already visible.
  2. 2. Access the VBA Editor: Click on 'VBA Editor' on the Developer ribbon to open the macro environment.
  3. 3. Create Your Custom Function: Insert a new Module, paste your VBA script, and immediately start using the custom formula in your spreadsheet cells.
Full compatibility with Microsoft Excel VBA macros and .xlsm filesFree, lightweight, and fast to download and installFamiliar ribbon interface ensures zero learning curveBuilt-in robust VBA editor for creating powerful automations
microsoft office alternative - wps office

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.