How to determine if a cell formula contains Constants?

Scheballs

When debugging or Quality Checking an Excel report at work I have found that the problem was because of text being hard coded inside a formula. I have heard this as being a Constant and Formula mixed cell.

Here are examples of what I see.

Constant =100

Constant =Facility

Formula cell =INDIRECT(ADDRESS(5,MATCH($A7&$B7&C$2,Data!$4:$4,0),,,$A$2))

Mixed cell =INDIRECT("Data!"&ADDRESS(5,MATCH($A7&$B7&C$2,Data!$4:$4,0)))

"Data!" is the Constant in the mixed cell, in this case the sheet name. If that sheet name ever changed, the formula would break. I have found and am using two conditional formats to highlight cells that are Constants and those that are formulas using this "Identify formulas using Conditional Formatting". I need to come up with a way to format those cells which contain these Constants inside of formulas.

I have found this question and tried using =IF(COUNT(SEARCH(CHAR(34),A1,1)),TRUE,FALSE) and FIND() to see if I could check if a cell had double quotes inside of it, but the SEARCH() returns FALSE since it is looking at the cells value and not it's contents. It returns TRUE if the cell contains "Constant" but if it is a formula it returns FALSE, such as if the cell contains ="Constant".

How can I find Constants inside formulas across a whole worksheet or workbook?

EDIT*

Thanks to Sidd's code below I have made a function in a module I can use in conditional formatting to at least highlight cells that contain quotes inside the cells.

Function FormulaHasQuotes(aCell)

  If InStr(1, aCell.Formula, """") Then
      FormulaHasQuotes = True
  Else
      FormulaHasQuotes = False
  End If

End Function

FormulaHasQuotes Conditional formatting pic

Siddharth Rout

Let's say your sheet looks like this.

enter image description here

Is this what you are trying?

Sub Sample()
    Dim ws As Worksheet
    Dim aCell As Range, FRange As Range

    '~~> Set this to the relevant sheet
    Set ws = ThisWorkbook.Sheets("Sheet1")

    With ws
        '~~> Find all the cells which have formula
        On Error Resume Next
        Set FRange = .Cells.SpecialCells(xlCellTypeFormulas)
        On Error GoTo 0

        If Not FRange Is Nothing Then
            '~~> Check for " in the cell's formula
            For Each aCell In FRange
                If InStr(1, aCell.Formula, """") Then
                    Debug.Print "Cell " & aCell.Address; " has a constant"
                End If
            Next
        End If
    End With
End Sub

When you run the above code, you get this output

Cell $A$2 has a constant
Cell $A$5 has a constant

Note: I have shown you how to do it for a sheet, i am sure you can replicate it for all sheets in a workbook?

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Reading a cell value that contains a formula returns 0.0 when using xlrd

From Dev

How to determine if a cell formula contains Constants?

From Dev

Using "If cell contains #N/A" as a formula condition.

From Dev

How to get fixed cell value, not formula?

From Dev

Formula to conditional formatting text that contains value from another cell

From Dev

How to change a formula according to cell value in excel?

From Dev

How to determine if a formula or a manual entry has been written in a cell

From Dev

How to re-calculate a cell's formula?

From Dev

How to clear cell if formula returns blank value?

From Dev

I want to use a variable which contains a cell reference within a formula

From Dev

How do I determine whether a cell in the first record of a customers history contains a value?

From Dev

How to run a formula on each cell in a range

From Dev

Determining if Excel cell contains array formula or text value

From Dev

How to color a cell in Excel using a formula?

From Dev

How dynamically to change the formula of a cell

From Dev

How to apply a formula to each cell of a numpy array

From Dev

Run formula only If cell contains a value

From Dev

How to shift the reference cell in a formula?

From Dev

Reading a cell value that contains a formula returns 0.0 when using xlrd

From Dev

Formula to conditional formatting text that contains value from another cell

From Dev

I want to use a variable which contains a cell reference within a formula

From Dev

Determining if Excel cell contains array formula or text value

From Dev

Can Excel use wildcards to determine if a cell contains specific text?

From Dev

Excel - Overflow the text of a cell to an adjacent cell that contains a formula

From Dev

How to refer within a formula to a cell that contains a wildcard?

From Dev

Differentiate between an empty cell and a cell which contains a formula

From Dev

Formula to ignore or treat as empty a cell that contains another formula with no result?

From Dev

Excel formula: If cell contains substring "this" AND does not contain substring "that"

From Dev

Replace whole cell with formula if it contains particular string

Related Related

  1. 1

    Reading a cell value that contains a formula returns 0.0 when using xlrd

  2. 2

    How to determine if a cell formula contains Constants?

  3. 3

    Using "If cell contains #N/A" as a formula condition.

  4. 4

    How to get fixed cell value, not formula?

  5. 5

    Formula to conditional formatting text that contains value from another cell

  6. 6

    How to change a formula according to cell value in excel?

  7. 7

    How to determine if a formula or a manual entry has been written in a cell

  8. 8

    How to re-calculate a cell's formula?

  9. 9

    How to clear cell if formula returns blank value?

  10. 10

    I want to use a variable which contains a cell reference within a formula

  11. 11

    How do I determine whether a cell in the first record of a customers history contains a value?

  12. 12

    How to run a formula on each cell in a range

  13. 13

    Determining if Excel cell contains array formula or text value

  14. 14

    How to color a cell in Excel using a formula?

  15. 15

    How dynamically to change the formula of a cell

  16. 16

    How to apply a formula to each cell of a numpy array

  17. 17

    Run formula only If cell contains a value

  18. 18

    How to shift the reference cell in a formula?

  19. 19

    Reading a cell value that contains a formula returns 0.0 when using xlrd

  20. 20

    Formula to conditional formatting text that contains value from another cell

  21. 21

    I want to use a variable which contains a cell reference within a formula

  22. 22

    Determining if Excel cell contains array formula or text value

  23. 23

    Can Excel use wildcards to determine if a cell contains specific text?

  24. 24

    Excel - Overflow the text of a cell to an adjacent cell that contains a formula

  25. 25

    How to refer within a formula to a cell that contains a wildcard?

  26. 26

    Differentiate between an empty cell and a cell which contains a formula

  27. 27

    Formula to ignore or treat as empty a cell that contains another formula with no result?

  28. 28

    Excel formula: If cell contains substring "this" AND does not contain substring "that"

  29. 29

    Replace whole cell with formula if it contains particular string

HotTag

Archive