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.
Related
I have an excel formula across a column for which the base changes every "x" number of rows. Note this "x" is not constant and keeps changing. e.g.
=D1/SUM(D$1:D$4)
=D2/SUM(D$1:D$4)
=D3/SUM(D$1:D$4)
=D4/SUM(D$1:D$4)
=D5/SUM(D$5:D$9)
=D6/SUM(D$5:D$9)
=D7/SUM(D$5:D$9)
=D8/SUM(D$5:D$9)
=D9/SUM(D$5:D$9)
I am trying to change the first part of the formulas without changing the second and vice versa. e.g. changing the numerator by 10 cells.
=D11/SUM(D$1:D$4)
=D12/SUM(D$1:D$4)
=D13/SUM(D$1:D$4)
=D14/SUM(D$1:D$4)
=D15/SUM(D$5:D$9)
=D16/SUM(D$5:D$9)
=D17/SUM(D$5:D$9)
=D18/SUM(D$5:D$9)
=D19/SUM(D$5:D$9)
or, changing the base by 100. e.g.
=D1/SUM(D$100:D$104)
=D2/SUM(D$100:D$104)
=D3/SUM(D$100:D$104)
=D4/SUM(D$100:D$104)
=D5/SUM(D$105:D$109)
=D6/SUM(D$105:D$109)
=D7/SUM(D$105:D$109)
=D8/SUM(D$105:D$109)
=D9/SUM(D$105:D$109)
Sometimes, both. Any guidance on how this can be possible?
Thank you.
the first part of this problem seems easy unless I am missing something?
Part 1:
Since the denominator is already in $x form, you can select and COPY the whole range of formulas and PASTE them 10 rows down and then CUT and paste it back into position. The COPY will update the numerators appropriately and when you CUT and PASTE it back into position they will now be just as you want? The second question will be a bit more of a challenge!
Part 2:
OK without VBA I can only think of a really long-winded way to change your demoninators, but I just checked that it does work:
To change the bottom.
Search and replace = with '=
Now you can edit the formulas more freely.
Search and replace D with D%
Search and replace D%$ with D
Search and replace D% with D$
get rid of the '= by using the Data>text to columns option
Now use the copy and paste, cut paste trick from part 1.
Then if you still need your $s back as they were you essentially repeat 1 to 5 again.
Sorry, this looks really long-winded, but if you are desperate and back up before you start it should work.
An excel formula can't replace another cells excel formula... One approach is to make the formula into text and then transform it by other formulas. When transformation is done, you could paste the formula back.
So for changing the D1 -> D11, I would build a dummy series (column K) then write a formula (cell L1). Then I can copy the formula and paste it into the correct column.
Replaceing the "=", with a special character and then you can transform the formulas.
(Column F).
In Column I, the formula used is: =RIGHT(F1,LEN(F1)-FIND("/",F1))
For changing D$1 -> D$100, I think I just would copy and replace it by searching in "Formulas".
This approach can be feasible for acouple of hundred cells. If the list is very long, I would recommend some VBA solution, where you can grab a cells formula with .Range("A1").Formula
I want to change the formulas in a 200x200 table by using find and replace.
My old formula is ='Sheet1'!A1*IF(B4=C2,1,0) and I want to replace it with =('Sheet1'!A1-'Sheet1'!B1)*IF(B4=C2,1,0)
Since doing it a cell at a time is tedious, I tried to use find and replace, but I could not keep the referenced cells. Is there a way to do it?
This is how the first cells of my data look like
I cannot fill down or right, since if I fill down I want to keep the reference to C2 while changing the reference to B4 (something like B4-$C$2), while if I fill right I want to keep the reference to B4 and change the reference to C2 (something like $B$4-C2)
I think I might have a bit of a workaround, I'd use it for one cell, and then mess about with the IF references depending on your needs for expanding down and right, as without seeing your dataset it's hard to envisage exactly how you want it, I hope this gives you the right idea, but may need a bit of messing about with.
Firstly, you want to get the cell with your original forumula in (let's say it's in A1). In an empty cell (let's say B1), you want to put =FORMULATEXT(A1). Then in another empty cell (let's say C1), you want to put:
="=(" & MID(B1,2,10) & "-Sheet1!B1" & ")" & MID(B1,11,20)
One thing to also maybe note is that my Excel doesn't produce quotes around the Sheet names, so you may need to mess about with the MID numbers (so probably change the 10 in the first mid to a 12, I think?) I've put the final MID number as 20 just to account for longer formulas.
Copy the cell. Now go to a new worksheet and in A1, you want to right click and paste values. Now, this part is important, you want to click into the formula bar and then press enter. This should now give the formula:
=(Sheet1!A1*-Sheet1!B1)*IF(B4=C2,1,0)
Now you can go into the formula bar, copy this and paste it back into your original sheet. Like I said, you should then mess about with the $ for the IF statement depending on your needs for expanding the data. Sorry it's a bit of a long workaround, but it's all I can find to do!
I have a matrix of data and each cell is a formula. All cell formulas are relative, so when I copy and paste just below, the formulas are now off.
Here's what I know works:
Change each cell's formula from relative to absolute
Copy the text from each formula, then paste this text below
I don't want to go and F4 each part of every formula for dozens of cells. Is there a way to copy paste a large batch but tell Excel to keep the exact formulas as written?
I personally do a bulk Find and Replace on the original range, replacing all "=" signs with a random text string which is guaranteed to not occur anywhere within those formulas, my usual choice being "##".
This converts all the formulas to text strings, after which you can paste the range before then performing the reverse Find and Replace, i.e. replacing "##" with "=", which coerces Excel into treating the strings as actual formulas once more.
Of course, if we're talking about a very large amount of formulas, i.e. several thousand, then this operation can take a while to perform, since not only is Excel required to carry out the Find and Replace on all strings, but also to calculate all the newly-created formulas.
Regards
When pasting, right click and choose "Paste Special" and use "Paste Formulas" (the fx icon).
Edit: Ah, I realize now this only works for 'fully anchored' ($A$1) cell references.
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 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.