I have numerous cells all over the place on a worksheet that look like =((E9-E8)/E8). I want to use the first two values to go into this new formula, (EXP((LN(E9/E8)/14.32))-1).
How can I change them all to the new formula in one fell swoop?
If the formulas are identical you can use Find and Replace with Match entire cell contents checked and Look in: Formulas. Select the range, go into Find and Replace, make your entries and `Replace All.
Or do you mean that there are several formulas with this same form, but different cell references? If so, then one way to go is a regular expression match and replace. Regular expressions are not built into Excel (or VBA), but can be accessed via Microsoft's VBScript Regular Expressions library.
The following function provides the necessary match and replace capability. It can be used in a subroutine that would identify cells with formulas in the specified range and use the formulas as inputs to the function. For formulas strings that match the pattern you are looking for, the function will produce the replacement formula, which could then be written back to the worksheet.
Function RegexFormulaReplace(formula As String)
Dim regex As New RegExp
regex.Pattern = "=\(\(([A-Z]+\d+)-([A-Z]+\d+)\)/([A-Z]+\d+)\)"
' Test if a match is found
If regex.Test(formula) = True Then
RegexFormulaReplace = regex.Replace(formula, "=(EXP((LN($1/$2)/14.32))-1")
Else
RegexFormulaReplace = CVErr(xlErrValue)
End If
Set regex = Nothing
End Function
In order for the function to work, you would need to add a reference to the Microsoft VBScript Regular Expressions 5.5 library. From the Developer tab of the main ribbon, select VBA and then References from the main toolbar. Scroll down to find the reference to the library and check the box next to it.
It turns out that the solution was to switch to R1C1 Cell Reference. My worksheet was structured in such a way that every formula had the same structure just different references. Luck though, they were always positioned the same way
=((E9-E8)/E8)
became
=((R[-1]C-R[-2]C)/R[-2]C)
and
(EXP((LN(E9/E8)/14.32))-1)
became
=(EXP((LN(R[-1]C/R[-2]C)/14.32))-1)
In R1C1 Reference, every formula was identical so the find and replace required no wildcards. Thank you to those who answered!
The way I typically handle this is with a second piece of software.
For Windows I use Notepad++, for OS X I use Sublime Text 2.
In Excel, hit Control + ~ (OS X)
Excel will convert all values to their formula version
CMD + A (I usually do this twice) to select the entire sheet
Copy all contents and paste them into Notepad++/Sublime Text 2
Find / Replace your formula contents here
Copy the contents and paste back into Excel, confirming any issues about cell size differences
Control + ~ to switch back to values mode
Use the find and replace command accessible through ctrl+h, make sure you are searching through the functions of the cells. You can then wildcards to accommodate any deviations of the formula. * for # wildcards, ? for charcter wildcards, and ~? or ~* to search for ? or *.
You can also click on the Formulas tab in Excel and select Show Formulas, then use the regular "Find" and "Replace" function. This should not affect the rest of your formula.
Related
I have created an expression using "&" to concatenate different cells, I created this:
=INDEX((Data_sheet!A1:M20440;Data_sheet!A20441:M40880;Data_sheet!A40881:M61320);20;5;D2)
Now, I have the expression that is a formula, but it is not evaluated as a formula when I paste it, I can see the whole expression in the cell, but I want to get is the value that is behind evaluating that formula. I want to know how to make it to evaluate as a formula (because I will have thousands of this expressions)
My guess is that you would have created the INDEX formula in excel using multiple other formulas.
Once you have created the formulas, copy all the formulas and paste it in a txt file. Then, copy all the formulas from txt file and paste it again in the excel where you want the formulas to perform. This is the simplest way of doing this without creating any macros or additional formulas
See this question for solutions:
How to turn a string formula into a "real" formula
In particular, also note the answer about Excel's hidden EVALUATE function, that can only be accessed after defining a name to use it.
https://www.vertex42.com/ExcelArticles/evaluate-function.html
Consider the following formula for cell A1
=Assumptions!$F$25*Assumptions!Q25
How can I create a boolean function to test if A1 has a reference to the sheet Assumptions?
I know if this was simply a constant, I could use: =+ISNUMBER(SEARCH("assumptions",A1) but this doesn't work if the cell value is a formula.
Note I am using EXCEL 2010, so isformula() won't work
Thanks
What about two alternative approaches?
Do a find a replace on the = sign. This will force all of your formulas to text, then you can write a normal formula to do the SEARCH or FIND. Then reverse the formulas back. I usually do a find all = and replace with ^^^ - then just reverse with find all ^^^ and replace with =.
If the heart of your question is just to find the references, why not use "find" CTRL+F ensure that Look in: Formulas is elected (under Options...), and then use the Find All button. This provides a nice list of output.
Say I have a row of 100 cells, each with some formula.
I want to copy them and paste them somewhere else, but with the formulas verbatim exactly the same, without changing the reference.
Is there a quick way to do this (i.e. without macros, without having to add $ signs to the formulas, etc.)? One might have thought that there is some way to do this through Paste Special, but I don't seem to see any such option.
The fastest way I usually do this is using find > replace...
Do something like this:
Select the cells that have the formulas you want
Use the find > replace feature in excel and replace all = with some other, unused character (I usually use #) - This will change them from formulas to plain text
Copy those cells and paste them where you want
Use the find > replace feature to replace that other character back to =
In effect, you are changing the formula to text, copying and pasting it as the plain text (so preserving the cell references), then changing it back to the original formula.
Hope this helps and makes sense.
I am horrible with excel. I rarely have to use it but today I do.
I have cells that have images that are comma separated. these cells are in the same column. i need to add a prefix lg_ to each comma separated image in the cell. I have done some reading on concatenate in excel and I am not sure if this is the right method to use. Does anyone have any good tricks/tips to accomplish this?
It currently looks like :
b3f9e6_1008a.jpg,4f57dc_1008d.jpg,9205eb_1008b.jpg,cb1c14_1008.JPG,ad8884_1008c.jpg
the result would look like this:
lg_75c552_599d.jpg,lg_a3a180_599a.jpg,lg_5c2ec4_599e.jpg,lg_dbb052_599b.jpg,lg_419420_599f.jpg,lg_8eb065_599c.jpg
note: images names are different because I just pasted what I already completed manually.
This should be on SuperUser.
What I would do is do Find..Replace on the comma and replace it with ",lg_" (without quotes). Then you need to prepend the strings with "lg_". You can do this by using another column and doing ="lg_"&A1 where you replace A1 with the proper cell reference. Drag this formula down and then copy and paste value that over the initial data.
Edit: Just because you seem new to Excel: To do Find..Replace hit Ctrl + H. The dialog box that will pop up is self explanatory.
This can also be done using the SUBSTITUTE command in a cell formula.
e.g.
Set C30 = "lg_"
Set D30 = "b3f9e6_1008a.jpg,4f57dc_1008d.jpg"
then in E30 type the following: =C30&SUBSTITUTE(D30,",",","&C30)
This does the same as ApplePie's answer, but with the added benefits that you do not need to do a manual replace, and "lg_" is not hard-coded so it can change depending upon the contents of a cell. Therefore you can copy the formula down a column and use different prefixes for each row. e.g.
IF C30="244" and D30="91,99" then E30 = "24491,24499"
IF C31="376" and D31="5,6,7" then E31 = "3765,3766,3767"
I've sorted a chunk of data into sub-totaled fields using the Subtotal tool under the Data tab. However, you are only able to choose one formula to apply.
How can I apply a separate formula to one of the columns based on SUBTOTAL(1,RANGE)? So far I have populated it with Subtotal (9,RANGE), but is there a quicker method to select all of these and change the "9" to a "1"?
Select the column.
Press CTRL+H.
Find What: SUBTOTAL(9
Replace with: SUBTOTAL(1
Click Replace All
Assume your formulae are in the range A1:A5
Open up the VBE by hitting Alt+F11, and enter the following code in a general module of the same workbook
Function GetFormula(Cell As Range) As String
GetFormula = Cell.Formula
End Function
I have got this code from http://dmcritchie.mvps.org/excel/formula.htm
For instructions on how to insert this code in a module, see the 'Where to put the code' section at http://www.cpearson.com/excel/writingfunctionsinvba.aspx
Now, you can extract the formula. Use this formula in a helper column, say column B
=SUBSTITUTE(GetFormula(A1),"(1,","(9,")
Now copy this formula upto where you need, and copy-paste values only back where required.
You can also use this trick to modify any other formulae you need, so I suggest you keep this snippet of code handy :)
Change first or last cell then copy it
select all other cells(you can use Ctrl+Shift+up, down, left or right) then use past special and chose formulas