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

How to determine if a cell formula contains Constants?

From Dev

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

From Dev

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

From Dev

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

From Dev

Run formula only If cell contains a value

From Dev

Replace whole cell with formula if it contains particular string

From Dev

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

From Dev

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

From Dev

Differentiate between an empty cell and a cell which contains 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 dynamically to change the formula of a cell

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

Determining if Excel cell contains array formula or text value

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

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

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

From Dev

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

From Dev

How to re-calculate a cell's formula?

From Dev

How to run a formula on each cell in a range

From Dev

How to color a cell in Excel using a formula?

From Dev

How to get fixed cell value, not formula?

From Dev

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

From Dev

How to clear cell if formula returns blank value?

From Dev

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

Related Related

  1. 1

    How to determine if a cell formula contains Constants?

  2. 2

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

  3. 3

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

  4. 4

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

  5. 5

    Run formula only If cell contains a value

  6. 6

    Replace whole cell with formula if it contains particular string

  7. 7

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

  8. 8

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

  9. 9

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

  10. 10

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

  11. 11

    How dynamically to change the formula of a cell

  12. 12

    How to shift the reference cell in a formula?

  13. 13

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

  14. 14

    Determining if Excel cell contains array formula or text value

  15. 15

    Formula to conditional formatting text that contains value from another cell

  16. 16

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

  17. 17

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

  18. 18

    Formula to conditional formatting text that contains value from another cell

  19. 19

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

  20. 20

    Determining if Excel cell contains array formula or text value

  21. 21

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

  22. 22

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

  23. 23

    How to re-calculate a cell's formula?

  24. 24

    How to run a formula on each cell in a range

  25. 25

    How to color a cell in Excel using a formula?

  26. 26

    How to get fixed cell value, not formula?

  27. 27

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

  28. 28

    How to clear cell if formula returns blank value?

  29. 29

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

HotTag

Archive