Search code examples
google-sheets-formula

Google Sheet: search for text in a cell, if true returns a value, if false returns 0


[1/28/2023,$5]Description

In my google sheet, a cell of a column has above value. I simply want to search "$5" in the cell, if it exists, then returns 5, otherwise returns 0.

=iferror(if(search("$5",N25)>0,5,0),0)

This is the formula I have managed to write. But it feels like it is redundant. Is there any better solution for this?


Solution

  • well if you wish to hardcode the value then try:

    =IFNA(REGEXEXTRACT(A2,"\$(5)"),0)
    

    if its to extract N value attached to $ then try:

    =IFNA(REGEXEXTRACT(A2,"\$(\d+)"),0)
    

    enter image description here