Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8222977
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T14:30:22+00:00 2026-06-07T14:30:22+00:00

For a given Excel formula in a cell, I’d like to be able to

  • 0

For a given Excel formula in a cell, I’d like to be able to parse the formula in order to get a list of Excel Range references contained within the formula.

For example, if I have a cell with this formula:

= A + 25 + B  

….I would like to be able to get an array of excel ranges contained within the formula, so in this case, it would contain [A] and [B]

“Why do you even want to do this”?, I can hear you asking:
Just one example of why I want to do this is to look up “labels” for ranges in formulas…..so, as opposed to just doing a CTRL+~ to view the formulas in my sheet, I’d like the option of programatically accessing the range references within the formula in order to do a lookup of the label beside the target range.

So, in my above example, I could then write formulas something like:

=Offset(CellFormulaRanges('TheAddressMyFormulaIsIn',1),0,-1)
=Offset(CellFormulaRanges('TheAddressMyFormulaIsIn',2),0,-1)

…which would give me the the label to the left of the 1st and 2nd ranges within the formula.

Doing this would have to call upon some functionality already within Excel itself, as hand writing a formula parser is a complicated task:
http://ewbi.blogs.com/develops/2004/12/excel_formula_p.html

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T14:30:25+00:00Added an answer on June 7, 2026 at 2:30 pm

    Thanks to @TimWilliams and @brettdj for pointing me in the right direction to previous discussions on this topic, I can confidently say:

    NO, EXCEL DOES NOT HAVE A METHOD FOR PARSING.

    However, for my fairly minimal purposes, I’ve come up with something that works, works with cross worksheet references, and can be called from a UDF.

    However, it is extremely brittle, and there are multitudes of perfectly legitimate formulas that I’m certain it wouldn’t handle properly.

    The code is a mess and could be greatly improved but I just wanted to throw it up on here as I’m moving onto to something else for the time being….

    EDIT

    Also found this, which looks very interesting:
    http://www.dailydoseofexcel.com/archives/2009/12/05/formula-tokenizer/

    Public Function CellPrecedents(cell As Range) As Variant()
        Dim resultRanges As New Collection
        If cell.Cells.count <> 1 Then GoTo exit_CellPrecedents
        If cell.HasFormula = False Then GoTo exit_CellPrecedents
    
        Dim formula As String
        formula = Mid(cell.formula, 2, Len(cell.formula) - 1)
    
        If IsRange(formula) Then
            resultRanges.Add Range(formula), 1
        Else
            Dim elements() As String
            'Debug.Print formula & " --> "
            formula = Replace(formula, "(", "")
            formula = Replace(formula, ")", "")
            'Debug.Print formula & " --> "
            elements() = SplitMultiDelims(formula, "+-*/\^")
            Dim n As Long, count As Integer
            For n = LBound(elements) To UBound(elements)
                If IsRange(elements(n)) Then
                    'ACTUALLY JUST DO A REDIM PRESERVE HERE!!!!
                    count = count + 1
                    'resultRanges.Add Range(Trim(elements(n)))  '<---  Do **NOT** store as a range, as that gets automatically Eval()'d
                    resultRanges.Add Trim(elements(n))
                End If
            Next
        End If
    
        Dim resultRangeArray() As Variant
        ReDim resultRangeArray(resultRanges.count)
        Dim i As Integer
        For i = 1 To resultRanges.count
            resultRangeArray(i) = CStr(resultRanges(i))  '// have to store as a string so Eval() doesn't get invoked (I think??)
        Next
    
        CellPrecedents = resultRangeArray
    
    exit_CellPrecedents:
        Exit Function
    End Function
    
    Public Function IsRange(var As Variant) As Boolean
        On Error Resume Next
        Dim rng As Range: Set rng = Range(var)
        If err.Number = 0 Then IsRange = True
    End Function
    

    (just google SplitMultiDelims for that function)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In the Excel Interop libraries, is there functionality to determine whether a given Range
I want to get the content of a cell given its row and column
I want to have a formula that calculates the sum of a given range.
I was given the following Excel formula to calculate the french system interest of
I have an Excel Workbook which has some VSTO-based c# code. Given a known
Can someone give me some code to set the cell of an excel spreadsheet
Given a date range how to calculate the number of weekends partially or wholly
has VBA any good mechanism for checking, if the content of a given Excel
I'm working with Ms. Excel. I have a cell contains a person name. Eg
I am having trouble constructing a unusual lookup formula in Excel. Normally, I would

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.