Please Note: This article is written for users of the following Microsoft Excel versions: 97, 2000, 2002, and 2003. If you are using a later version (Excel 2007 or later), this tip may not work for you. For a version of this tip written specifically for later versions of Excel, click here: Checking for Proper Entry of Array Formulas.

Checking for Proper Entry of Array Formulas

Written by Allen Wyatt (last updated October 27, 2020)
This tip applies to Excel 97, 2000, 2002, and 2003


Jeffrey's company has a number of reports that use an extensive number of CSE (Ctrl+Shift+Enter) array formulas. When someone forgets to hold Ctrl and Shift when pressing Enter, the resulting formulas do not equal the correct answer. Auditing each cell, looking for the { } brackets is both tedious and time consuming. Jeffrey wonders if there is a quick way to find the "missing brackets" or raise an error flag if Ctrl+Shift+Enter is not pressed when it should be?

There is no intrinsic or formulaic method of doing this in Excel. This means that you need to turn to a solution that is based on a macro. Fortunately, VBA offers several different ways you can approach this problem. One approach is to simply use a formula to make sure that each formula within a selection is actually an array formula.

Sub MakeCSE1()
    Dim rCell As Range

    For Each rCell In Selection
        rCell.FormulaArray = rCell.Formula
    Next rCell
End Sub

This macro assumes that you'll select the cells to be "converted" before actually running the macro. If you prefer, you could define a range of cells (give the range a name) and then run a similar macro that always does its work on that range.

Sub MakeCSE2()
    Dim rng As Range
    Dim rCell As Range
    Dim rArea As Range

    Set rng = Range("CSERange")
    For Each rArea In rng.Areas
        For Each rCell In rArea.Cells
            If rCell.HasArray = False Then
                rCell.FormulaArray = rCell.Formula
            End If
        Next rCell
    Next rArea
End Sub

This macro looks for a range named CSERange and then checks every cell in the range. If it doesn't contain an array formula, then the formula is converted to an array formula.

Note the use of the HasArray property to check if a cell contains an array formula. This property can actually be helpful in other ways. For instance, you could create a simple user-defined function, such as this:

Function NoCellArray1(rng As Range) As Boolean
    NoCellArray1 = Not rng.HasArray
End Function

This function returns True if the cell being pointed to doesn't contain an array formula. If it does contain one, then False is returned. You could then use this function as the basis for a conditional format. All you need to do is create a format that uses it in this way:

=NoCellArray1(A5)

Since NoCellArray returns True if the cell doesn't contain an array formula, your conditional format could set the color of the cell to red or set some other visible sign that the cell doesn't have the requisite array formula. You could also use the following function to accomplish the same task:

Function NoCellArray2(rng As Range) As Boolean
    NoCellArray2 = (Evaluate(rng.FormulaArray) <> rng.Value)
End Function

An entirely different approach is to add something to your formulas that allows them to easily be recognized as array formulas. For instance, you could add the following to the end of any of your array formulas:

+N("{")

This doesn't affect the computation in any way, but can be easily checked to see if it is there. The checking can be done by an event handler, such as the following:

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    If Right(Selection.FormulaArray, 5) = "(""{"")" Then
        ActiveCell.Select
        Selection.FormulaArray = ActiveCell.Formula
    End If
End Sub

Note that the handler checks to see if the formula ends with ("{") and, if it does, forces the formula to be treated as an array formula. The great thing about this approach is that you'll never have to press Ctrl+Shift+Enter on the worksheet again—the event handler takes care of it for you. If, at some point, you want to convert the formula back to a regular (non-array) version, simply modify the formula so it doesn't include +N("{").

Note:

If you would like to know how to use the macros described on this page (or on any other page on the ExcelTips sites), I've prepared a special page that includes helpful information. Click here to open that special page in a new browser tab.

ExcelTips is your source for cost-effective Microsoft Excel training. This tip (473) applies to Microsoft Excel 97, 2000, 2002, and 2003. You can find a version of this tip for the ribbon interface of Excel (Excel 2007 and later) here: Checking for Proper Entry of Array Formulas.

Author Bio

Allen Wyatt

With more than 50 non-fiction books and numerous magazine articles to his credit, Allen Wyatt is an internationally recognized author. He is president of Sharon Parq Associates, a computer and publishing services company. ...

MORE FROM ALLEN

Splitting Text to Multiple Cells

When processing data, you may have a need to split a long text string into shorter chunks of text consisting of whole ...

Discover More

WordTips: The Macros (Special Offer)

WordTips: The Macros can help you discover the power and capabilities of macros within the word environment. ...

Discover More

Creating a Numbered List

Numbered lists provide a 1-2-3 way of organizing your document. You can create numbered lists very easily using the ...

Discover More

Program Successfully in Excel! John Walkenbach's name is synonymous with excellence in deciphering complex technical topics. With this comprehensive guide, "Mr. Spreadsheet" shows how to maximize your Excel experience using professional spreadsheet application development tips from his own personal bookshelf. Check out Excel 2013 Power Programming with VBA today!

More ExcelTips (menu)

Finding Differences Between Lists

A common task faced by Excel users is to determine whether items in one list are also found in a different list. There ...

Discover More

Getting a Count of Unique Names

When you've got a column full of names, you may want to get a count of how many of those names are unique. You can make ...

Discover More

Totaling Across Worksheets

Want to sum the values in the same cell on a range of worksheets? It's not as easy as summing a range on the same ...

Discover More
Subscribe

FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."

View most recent newsletter.

Comments

If you would like to add an image to your comment (not an avatar, but an image to help in making the point of your comment), include the characters [{fig}] (all 7 characters, in the sequence shown) in your comment text. You’ll be prompted to upload your image when you submit the comment. Maximum image size is 6Mpixels. Images larger than 600px wide or 1000px tall will be reduced. Up to three images may be included in a comment. All images are subject to review. Commenting privileges may be curtailed if inappropriate images are posted.

What is 2 + 2?

There are currently no comments for this tip. (Be the first to leave your comment—just use the simple form above!)


This Site

Got a version of Excel that uses the menu interface (Excel 97, Excel 2000, Excel 2002, or Excel 2003)? This site is for you! If you use a later version of Excel, visit our ExcelTips site focusing on the ribbon interface.

Newest Tips
Subscribe

FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."

(Your e-mail address is not shared with anyone, ever.)

View the most recent newsletter.