I am trying to write a code that is like find and replace within formulas. Essentially, I have all these cells that reference other workbooks yet the same cells. I need a code that replaces the middle terms which begin after the first 18 characters and end where there is a "]" and then is replaced by a specific cells value that is referenced. For ex. the original cells formula is
=userbush/dropbox/dallasloop[garden.xlsm]Profit!k!5!
and I want to replace that formula with
=userbush/dropbox/dallashouse[kitchen.xlsm]Profit!k!5!
That being said I have a cell that has dallashouse[kitchen.xlsm so that input cell can by dynamic and changed. In all, I am trying to create a code the finds and deletes certain character between two constraints and replace it with values that are within a referenced cell.
Related
I have made an error when copying formulas across multiple columns and need to correct them. The issue is I have multiple breaks in the rows so I can't just drag the formula down for each column.
If I use search and replace to change the letter, it also replaces all other letters within the formula.
Is there a way to just change the cell reference letter?
Example:
=VLOOKUP(C10,CAT!A:C,3,FALSE)
If I find and replace C, as I need to change it to D10, I end up with =VLOOKUP(D10,DAT!A:D,3,FALSE) but need to end up with =VLOOKUP(D10,CAT!A:C,3,FALSE)
Any help would be very much appreciated as it is a very large spreadsheet and I am dreading doing it manually.
Cheers
I have a spreadsheet full of references, pretty much every permutation you can imagine.
EX:
='January Scorecard'!F7
='February Scorecard'!F7
='March Scorecard'!H7
='April Scorecard'!H7
I want to be able to change specific things of the formula across an entire row or column. So if I need to change a row where all of the references currently point to 'H7', I want to be able to quickly change all of them to 'F31' or another arbitrary cell value.
What are quick ways to change cells specifically while keeping the reference sheets the same?
You need to use the INDIRECT function. This takes a cell reference which contains text representing a cell address, and converts it into that cell address. So if cell A1 had the text "H7", then your example cells would now have
=INDIRECT("'March Scorecard'!" & A1)
whcih would firstly convert to "'March Scorecard'!H7 " and then the indirect would convert it to ='March Scorecard'!H7
I am working in Excel and I am wanting to find out if there are matches in one sheet based on a list in the other sheet.
I have pasted the values in a list and want to return their corresponding value from another sheet. The cells that contain letters and numbers work correctly (example: D5765000), but for some reason if the cell has only numbers, Excel is not able to find it in the other sheet, even though it exists.
I pasted a value 745‐3000 in the list and I am looking for this corresponding value in another sheet. It shows as #N/A on the lookup indicating it doesn't exist in the other sheet. However, if I delete the 745‐3000 and manually type 745-3000, then Excel somehow does recognize the value and find it in the other sheet.
The formatting is exactly the same in both and there are no spaces in either list. I cannot understand why Excel won't recognize the pasted value of 745-3000. Any ideas?
Excel is reading the "-" with a different code than it is with a manually typed "-"
Isolate the "-" and use to find and replace. Does some data contain multiple offending "-"'s?
=REPLACE(H4,FIND(G4,H4),1,"-")
EDIT: Switched from code to Unicode
TY #ron
We find the offending char using the set up pictured below:
Some of the formulas used:
Yellow Cells:
=UNICODE(MID($A$3,C4,1))
Light Blue Cells:
=UNICODE(MID($E$3,C4,1))
At the bottom we check to see what code we get from the value. I get a VALUE mark with from the unicode value of "-"
I have a cell number as a string ("A1") in a formula, and this needs to be changed relatively while copying, like it does automatically to normal cell references. so I don't have to visit 400 cells and change them all by hand.
Any way I can manage this? Thanks for the help.
Formula I am using in 400 cells:
=IF(IDENTIC($M$10;"Entries are correct.");IF(ISNUMBER(FIND("A1";$N$5));"S1";IF(ISNUMBER(FIND("A1";$N$6));"S2";IF(ISNUMBER(FIND("A1";$N$7));"S3";IF(ISNUMBER(FIND("A";$N$8));"S4";IF(ISNUMBER(FINDEN("A1";$N$9));"S5";"")))));"")
I don't want to change every single cell as text in all 400 cells, it should change relatively as normal cell references do.
To get a cell reference as a string in Excel you can use the CELL function:
=CELL("address";A1)
Since the second parameter to the function is an actual cell reference, if you copy and paste this formula it will auto-update accordingly.
Bear in mind this will return a string containing an absolute address so it will return "$A$1", not "A1".
CELL(...) will work.
More generally, you can also build the formula as strings using concatenations. This can be useful when you have a list of stuff and you would like to have formulas that refer to those names. Or in your case it would also work.
Building the formula as string with concats & then search & replace
First I build up as much as I can the formula so that the general structure is already formed (only the reference you'll want to change will not be final):
Using your case as an example:
Then, I wrap that nearly-formed formula into a CONCATENATE(). I then arrange things to have a references that I will point to within that CONCAT() that will auto-increment to the text I actually want to include in my formula. Something like this:
=CONCATENATE("IF(FIND(""",A1,"""$A$4),TRUE, FALSE)")
The ,A1, refers to the actual cell, so that cell's content is what will be included in my formula. You can then increment this all the way to build the proper formula for each cell (the 400 ones in your case). You need the triple """ because you want to actually include A1, B1 etc... are text references, not cells.
Then, all you need to do is selected all those formulas, copy them & make sure to choose past as values, say the line under (to keep you concatenate intact so you can edit it later if needed). Then with that pasted line all selected, you use a find & replace to add an "=" sign to the beginning of formulas. Better be too specific on the find & replace, so find "IF(F" and replace by "=IF(F" or similar. Then magic happens:
You can see that A1, C1, D1 have returned TRUE while the rest are #VALUE! because the find method has failed to find the string.
How does one cell obtain the formula of another cell as text without using VBA? I can see this question has already been asked many times and the answer is always to write a custom function in VBA.
However, I found a post made in 2006 which claimed to have found the non-VBA solution but the link provided in that post is already broken.
=FormulaText(Reference) will do the trick Documentation
There is nice way of doing this without VBA. It uses XL4 macros (these are macros, but it is not VBA, as asked).
With reference to the figure 1, cells A2:A4 contain usual formulas.
Going to Formulas -> Define Name, I defined two named ranges (see fig. 2), with the information shown in cells A6:B8.
Enter in cell B2 =FormulaAsText. This will retrieve the formula in cell A2 as text.
Explanation:
The named range FormulaAsText uses =GET.CELL(info_type,reference). In this case, ìnfo_type = 6 retrieves the formula, and reference = OFFSET(INDIRECT("RC",FALSE),0,-1) uses the cell with 0 rows and -1 columns offset from the one the formula is used in.
Copy B2 and paste into B3:B4. This will show formulas in A3:A4. Cell A4 shows that the worksheet function CELL only retrieves values, not formulas (as opposed to GET.CELL).
Since FormulaAsText gets the formula from a cell at fixed offset (0,-1) from the current, I defined another range FormulaAsText2, which uses an offset (rows,cols) read from the worksheet itself. Cells D2:D4 contain =FormulaAsText2. Thus, cell D2 shows the contents of cell B3 (=OffSET(D2,1,-2)), which is FormulaAsText. cells D3:D4 show the contents of themselves. This adds some flexibility. YMMV.
PS1: The essence was taken from
http://www.mrexcel.com/forum/excel-questions/20611-info-only-get-cell-arguments.html
PS2: Tim Williams mentioned in a comment "the old XLM GET.FORMULA()". This answer is possibly related (not the same, since this one uses GET.CELL()).
PS3: A simple VBA solution is given, e.g., in
http://dmcritchie.mvps.org/excel/formula.htm
EDIT: Complementing this nice answer, the worksheet function FormulaText is available for Excel 2013 and later.
This suggestion may be helpful for those who after retrieving a block of formulas and transporting them to a new spreadsheet want to put them to work again. Excels FORMULATEXT function is great for picking up formulas but it leaves them as unusable text strings. If you want to get them back as fully functioning formulas you have to edit each one individually to remove the string character, but here is a shortcut for larger blocks.
Get to the position where you have the required formulas as text (in other words after using FORMULATEXT - you have done a copy and (value only) paste). The next step involves highlighting all the cells you want to convert and then navigating to the [Text-To-Columns] menu option ({Data} bar on Excel 2016). You can select 'Delimited' but on the next screen just make sure you de-select any marks that do appear in your formulas. Then 'Finish'. Excel should automatically analyse the cells as containing formulas and you should now have them working again.
There is a way to do this. In my example I had a table that showed a date. The date comes from Sheet!G91. In my table I also had a column that showed the sheet name. I added two more columns to my table. The first column had column(Sheet!g91), which returns the number 7, because G is the seventh letter in the alphabet. I then converted the number to a letter (G) using another table in my workbook. In the second column that I added, I made a formula row(Sheet!G91), which returns the number 91. Note: Row and Column may appear as volatile formulas, which recalculate with every calculation of the workbook.
I wanted another column to show the formula contents of the date cell mentioned at the beginning of this post. I included the following string function (you can also use CONCATENATE).
"=" & AJ9 & "!" & AM9 & AN9
The items separated by ampersands get strung together (that is, concatenated). AJ9 in my example contains the sheet name, AM9 contains the column letter, and AN9 contains the row number.
I now have a column that dynamically updates its contents to reflect the sheet name and cell reference. The results in my workbook cell are
=Sheet!G91.
You can't. This is most likely a design choice to eliminate an average Excel user from accidentally getting something they did not want.
What you are reading is correct - writing a UDF is the solution you want.