Evaluate an expression as a formula in Excel - excel

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

Related

Excel SUMIFS formula with reference to other workbook

Im trying to write a VBA code for which will fill my excel SUMIFS formulas.
In general SUMIFS will calculate sums based on other workbook data.
Other workbook filename is currently hardcoded in my macro, however i'd like to make it more flexible and instead of hard coding it i'd like to use a cell in which i put the file name.
so far macro creates the following formula and puts it in cell:
=SUMIFS([SW.xlsx]TeamAllocations!F$9:F$401,[SW.xlsx]TeamAllocations!$D$9:$D$401,$D16,[SW.xlsx]TeamAllocations!$B$9:$B$401,$B16)
what i'd like to have is kind of:
=SUMIFS([<variable evaluated based on a cell which has filename/filepath, eg B1>]TeamAllocations!F$9:F$401,[<variable evaluated based on a cell which has filename/filepath, eg B1]TeamAllocations!$D$9:$D$401,$D16,[<variable evaluated based on a cell which has filename/filepath, eg B1]TeamAllocations!$B$9:$B$401,$B16)
So in B1 cell i'd have "SW_01.xlsx" or "SW_02.xlsx", so the SUMIFS formula will always have up-to-date soruce.
Is that possible in excel?
Thanks
J.
If all your files have a fixed format, I think you can combine all of the files with power query.
You can do what you want more easily.
Combine Files:
https://chandoo.org/wp/combine-excel-files-using-power-query/
Group in PowerQuery (same as SUMIF):
https://support.office.com/en-us/article/group-rows-in-a-table-power-query-e1b9e916-6fcc-40bf-a6e8-ef928240adf1
Useful filter:
https://exceleratorbi.com.au/pass-excel-parameter-power-query/

Why does my Conditional Formatting fail when it works in Worksheet? Possible INDIRECT issue?

I am trying to do a comparison/Conditional Formatting between columns based on a drop-down choice. I have a formula that works fine in the spreadsheet, but does not seem to be working in my Conditional Formatting formula. Is INDIRECT causing my issue?
Formula is:
=IF(H1>100, IF((H1-INDIRECT(ADDRESS(ROW(H1), MATCH($H$4,$A$3:$I$3,0))))/((H1+INDIRECT(ADDRESS(ROW(H1), MATCH($H$4,$A$3:$I$3,0))))/2)>$J$2,TRUE,FALSE),FALSE)
Kind of hard to read, but the part that broke it is trying to grab my comparison cell using the following:
INDIRECT(ADDRESS(ROW(H1), MATCH($H$4,$A$3:$I$3,0)))
Where $H$4 is my drop-down value. So I am selecting the column that contains the data I want to compare to, then using address to select the current rows cell, then accessing it with INDIRECT.
If I replace the INDIRECT part with an actual cell, everything works as it should as well.
When I use the first formula, everything looks great if I input it into a cell on the worksheet, but I would rather not dirty it up if I don't have to. Is there a way to make this work?

How to translate this formula translated into VBA?

I have this formula below that I am attempting to use to perform different calculations depending on the data in the referenced cells. The formula works, but I need to have more flexibility on the data found.
=IF(AND(U1="APO 300%",$E2="P+"),P2-(SUMIF($F$2:$F$74,300%,H$2:H$74)*M2)-(SUMIF($F$2:$F$74,150%,H$2:H$74)*M2),IF(AND(U1="APO 300%",$E2="P"),H2,""))
Is there a code that can duplicate this?
Worksheets have an Evaluate method which can be used to do what you want:
shtObject.Evaluate("A1+B1") '<<< substitute in your formula

Alternative to INDIRECT

I'm using the INDIRECT function to fetch data from another table sheet.
The direct way would be "sheetname!A5". I need it dynamically, so the sheetname is also part of the table, using indirect "indirect("'"&G$1&"'!A5"), whereas G1 contains the sheetname works fine.
INDIRECT is horribly slow, which outperform my project because I need a lot of fetches.
Is there a less powerful / more performant function to fetch data from variable sheets?
I've run into similar situations - depending on how frequently your 'results' worksheet changes, it may be best to create a formula dynamically that initially 'writes' hardcoded formuls. For example: ="='"&G$1&"'!A5".
Then copy that formula as you wish; it will create text strings that represent what you want the formulas to look like. Then copy & paste as values - you will now have the desired formula entered into each cell. By default, Excel will still display each cell as a text string, even though the format type would be general (assuming it was beforehand). From there, different solutions are possible - if you have few enough cells it may be enough to just start at the top pressing F2 then Enter, repeatedly, to get Excel to calculate each cell.

A formula to copy the values from a formula to another column

I have a column of values created from a formula, I know I can copy the values over to another column by using the clipboard. BUT...I want my spreadsheet to be automatic whilst avoiding the use of VBA coding, so it would be ideal if I could create a formula for the next column which copies the VALUES over to the next column. Maybe an INDEX/MATCH kind of method but one that copies ONLY the values rather than the formulas.
So in essence I want a formula to copy the values from a formula....
You can use =A4, in case A4 is having long formula
Use =concatenate(). Concatenate is generally used to combine the words of several cells into one, but if you only input one cell it will return that value. There are other methods, but I find this is the best because it is the only method that works when a formula, whose value you wish to return, is in a merged cell.
For such you must rely on VBA. You can't do it just with Excel functions.
you can use those functions together with iferror as a work around.
try =IFERROR(VALUE(A4),(CONCATENATE(A4)))
What about trying with VLOOKUP? The syntax is:
=VLOOKUP(cell you want to copy, range you want to copy, 1, FALSE).
It should do the trick.
Copy the cell. Paste special as link. Will update with original.
No formula though.

Resources