Evaluate if the formula in a cell contains a character - excel-formula

How do I search a cell for specific text in its formula(not the cell output) using Excel 2010. For example…I need to know if the highlighted cell has a “/” in the formula.
In this case the answer would be "No" or "False"
I have tried a few different options that all seem to search the cell output for the character instead of the cell formula. Here is what I have tried that does not work:
=ISNUMBER(SEARCH("/",A1))
=SUBSTITUTE(A1,"/","") <> A1

If you have a recent version of Excell (> 2010) you can use the function FORMULATEXT like here:
=ISNUMBER(SEARCH("/",FORMULATEXT(A1)))
Otherwise you can replace that with a VBA function:
Function FormulaText(mycell As Range)
FormulaText = mycell.Formula
End Function

Related

How to pull specific data from different length string?

I got this type of sport activity data in excel:
I try to pull just a "calorie" value from column D to another cell.
Any suggestions how to pull this data?
Tried to do it by =MID function, but those strings are different length.
Any suggestions how to pull this data?
You could try a formula like as below,
• Formula used in cell E1
=TEXTAFTER(TEXTBEFORE(D1,",""count"),"calorie"":")+0
Alternative approach, If you are not using MS365, then use the formula as shown below
• Formula used in cell F1
=REPLACE(LEFT(D1,FIND("""count",D1)-2),1,FIND("calorie",D1)+8,"")+0
Or, In MS365 using CHOOSECOLS() & TEXTSPLIT()
• Formula used in cell G1
=CHOOSECOLS(TEXTSPLIT(D1,{":",","},,1),8)/1
=TEXTBEFORE(TEXTAFTER(A1,"""calorie"":"),",")
Using VBA, you can use the Split method, since the pattern is the same:
Sub ExtractCalorie()
Dim cel As String: cel = ActiveCell.Value
'in the active cell is the string: {"duration":67,"altitude":0.0,"distance":21499,"calorie":89000,"count":0,"floor":0,"steps":0}
Debug.Print Split(cel, ",")(3) 'it returns "calorie":89000
'If only the value needed:
Debug.Print Split(Split(cel, ",")(3), ":")(1) 'it returns 89000
End Sub
It can be easily transformed in a function, which works also as UDF, to be called from a formula in cell...

using Application.WorksheetFunction.MRound and Cells.Formula

I am trying to write excel formulas using Cells.Formula and Application.WorksheetFunction.MRound
I want to leave the formulas in the cells but it only leaves the values, not the formulas.
How do I leave the formulas in the cells?
The Application.WorksheetFunctions are not meant to be placed into cells, but will perform the calculation of a worksheet function in VBA.
If you want to place a formula into a cell you need to use one of the Formula properties, for example
Range("A1").Formula ' or
Range("A1").FormulaR1C1
See this question for an example of both.
Instead of cell.value = Application.WorksheetFunction.MRound use cell.formula = "=MRound". I.E. put the formula as you'd write it in a cell into the cell as a string.

Excel return formula from Cell

Need help making a function that returns the equation of a cell without the equal sign. Can be done in google sheets, Excel, VBA, or Google App Scripts.
Example below
Instead of typing out A1+A2, can I type a formula into cell C1 that returns string A1+A2 from cell B2.
B2 Formula =A1+A2
C2 Value I would like A1+A2
example
Try this quick user defined function.
function whatFormula(rng as range)
set rng = rng.cells(1)
if rng.hasformula then _
whatFormula = mid(rng.formula, 2)
end function

eXcel formula for all column value in one cell separating by ","

Look at the column A contain value like the below image . I want a formula to do that .
I don't want to solution like
=CONCATENATE(A1,",",A2,",",A3,",",A4,",",A5)
Excel 2016 has a new function called TextJoin() with the syntax
=TextJoin(delimiter, ignore empty cells, range)
With this, you can use the formula
=TEXTJOIN(",",TRUE,A1:A5)
Edit after comment: It's a new formula in Excel 2016. It does not exist in 2010.
But there are many User Defined Functions (UDF) macros that do a better job than Concatenate, and that can be used in Excel 2010. For example in this post by Jon Acampora. You will need to use the VBA code in each of the spreadsheets where you want to use that special function, though, and all these spreadsheets need to be macro-enabled sheets for these special functions to work.
try this
=A1&","&A2&","&A3&","&A4
OR create custom VBA function
Public Function Join(rng As Range, delimiter As String) As String
Dim cell As Range
For Each cell In rng
Join = Join & cell.Text & delimiter
Next cell
' remove the last delimiter
Join = Left(Join, Len(Join) - Len(delimiter))
End Function
For a long list a more complex formula but one that 'auto adjusts' on copy down might suit:
=IF(A2="",LEFT(B1&A2&",",LEN(B1&A2&",")-2),B1&A2&",")
Assumes a row is inserted at the top with B1 blank. The output would be in ColumnB of the row with the first blank cell in ColumnA after Row1.

Extract Argument or String from Excel Formula - Excel 2003

I need to do a Mid or Find on a cell formula rather than cell contents.
If my cell formula is:
=[Func](Arg1, Arg2, Arg3)
I need to be able to extract say Arg2 to another cell.
Is this possible without using VBA or a special Excel Add-In?
I've tried using the Cell but there is no option to return the formula a cell contains, if I could just break that formula out as a string to another cell I would be able to use Mid and Find etc.
Any Ideas?
Cheers
Yes, this is indeed one of those cases, where only a UDF (user defined formula) does the trick. Here a possible function (not too sophisticated); you could certainly add more of your required processing into this UDF.
Function FormulaText(cell As Range, _
Optional default_value As Variant)
' Returns the formula of the top leftmost cell in range as text
' default_value Value to return, if cell is empty
Set cell = cell.Resize(1, 1)
If cell.Formula = "" And Not IsMissing(default_value) Then
FormulaText = default_value
Else
FormulaText = cell.Formula
' If using a non-Englisch Version of Excel, cell.FormulaLocal
' returns the Formula in the localized format
' instead of e.g.
' =SUM(C7, C9) in my case it would return
' =SUMME(C7;C9)
End If
End Function
Open the Visual Basic Editor (Alt + F11), create a new module and paste the code into the edit area.
Use in Excel:
=FormulaText(A1, "No formula") with default value if referenced cell is empty
=FormulaText(A1) without default value
=FormulaText(A1:B3) return only the formula from A1
HTH
Andreas

Resources