EXCEL - Circular Reference Error when Entering Data - excel

I've got another one that is really kicking my butt.
I know why the error is occurring. I just don't know how to fix it. There are a lot of IF statements so I'm thinking maybe they are arranged in a way that is causing the error. I'm sure there is a much cleaner way to write them.
Whenever I try to input data into D7 or E7 I get the circular reference error.
These are my current formulas for all relevant cells:
F7: =IF(C7<0,"FAIL",IF(OR(ISBLANK(B7),ISBLANK(C7))," ",IF(ABS(F8)<=30,"PASS","FAIL")))
G7: =IF(D7<0,"FAIL",IF(OR(ISBLANK(B7),ISBLANK(D7))," ",IF(ABS(G8)<=30,"PASS","FAIL")))
H7: =IF(E7<0,"FAIL",IF(OR(ISBLANK(B7),ISBLANK(E7))," ",IF(ABS(H8)<=30,"PASS","FAIL")))
F8: =IF(B7<0,"",IF(C7<0,"",IF(D7<0,"",IF(E7<0,"",IF(G7="FAIL","",IF(H7="FAIL","",IF(ISBLANK(B7),IF(ISBLANK(C7),"","input Lw_Lw"),IF(ISBLANK(C7),"input Lw_Up",SUM(C7-B7)))))))))
G8: =IF(B7<0,"",IF(C7<0,"",IF(D7<0,"",IF(E7<0,"",IF(F7="FAIL","",IF(H7="FAIL","",IF(ISBLANK(B7),IF(ISBLANK(D7),"","input Lw_Lw"),IF(ISBLANK(D7),"input Up_Lw",SUM(D7-B7)))))))))
H8: =IF(B7<0,"",IF(C7<0,"",IF(D7<0,"",IF(E7<0,"",IF(G7="FAIL","",IF(F7="FAIL","",IF(ISBLANK(B7),IF(ISBLANK(E7),"","input Lw_Lw"),IF(ISBLANK(E7),"input Up_Up",SUM(E7-B7)))))))))
Snip of Excel table
Any help would be much appreciated!

I worked out the following two formulas for you. Please try them.
[F7] =IF(IFERROR(ABS(F8)<=30,FALSE),"PASS","FAIL")
[F8] ==IF(ISBLANK(C7),"input "&F$3,IF(OR(COUNT($B7:$E7)<4,COUNTIF($B7:$E7,"<0")>0),"",SUM(C7-$B7)))
Copy them from F7:F8 to G7:H8.
The basic principle I applied in order to avoid a circular reference is to do all testing in row 8 with the outcome that F8 will either hold a blank or a number. Therefore "Pass" or "Fail" in row 7 can be decided based on the number: If the number is within range it's a PASS, else it's failed. Note that Abs("") will cause an error. Therefore IFERROR(ABS(F8)<=30,FALSE) will return False in case F8 = "". Effectively, this is the reverse of what I wrote in my comment above.
I looked for shorter expressions for other tests as well. Count() will only count cells with numbers in them. Therefore I use this function instead of a series of ISBLANK() queries. Similarly for COUNTIF($B7:$E7,"<0").
I used mixed absolute and relative addressing to enable copying formulas to other columns and referred to the column captions in place of repeating the same texts in the formulas.
I didn't fully test my solution. However, with my above explanation as a guide you should be able to take possession and eliminate any errors I might have left behind.

Related

Basic IF Statement question -probably right in front of me

Sorry i know this is super basic but i didn't know where else to ask and i really feel like the answer is right in front of me...
I have a spreadsheet which im going to use to log PAT test results. When i select the test type from a drop down it changes the standards and thresholds in the bit below and will tell me if each test passes or fails. It uses several vlookups and relative references - so far no VBA. Looking at this photo. What I'm trying to do is get the formula in cell I13 to read the symbol in F13 and use that in the formula rather than typing the symbol directly into the formula as its going to change when i change the Class Type option.
So far ive gotten to this (has a blank IF to start with to keep it neat:
=IF(H13="","",IF((H13&F13&(VALUE(G13))),"PASS","FAIL"))
The bit in bold is where the issue is. When i run the evaluate formula it boils the bold bit down to "0.01>2" which is correct however it then wont read that in the larger IF statement - i think its the quotation marks. So i think it needs another function to allow the IF statement to read that as the logical test rather than a text string.
I've tried VALUE, FORMULATEXT, NUMBERTEXT, all the ones that might be close to what I'm trying to do but 100% stumped now. Always bring sup the #VALUE Error.
Appreciate any advice? TIA
There is no built-in function for that. You need either a VBA function or the old EVALUATE XLM function (which you can't use directly in a cell, it has to be in a defined name). Sample UDF:
Function EvaluateFormulaString(FormulaString as string)
EvaluateFormulaString = application.evaluate(formulastring)
End Function
then your formula would become:
=IF(H13="","",IF(EvaluateFormulaString(H13&F13&(VALUE(G13))),"PASS","FAIL"))

Keep same value of all merged cells

I don't know why every time I fall in love with a program because I found it very useful at first use, but I end up always struggling of its stupidity after a depth use.
So, my journey begins with the excel function "Merge & Center" that warns me that it will only keep the top left value and delete the others, which is very stupid because I can no longer drag a function in a cell to the others, did no one in this planet suggested that it will be way easier to keep the same value in each merged cells or to put at least a simple checkbox to give the user the option to choose between the two outcomes.
Ok, before I come to this forum I did some research, found a lot of VBA codes, tricks, methods but none gave me the satisfaction that I'm looking for, I concluded that it's impossible to merge and keep values in cells, so can someone please explain to me why Microsoft didn't think of that?
Here is a simple example of what I'm looking for:
enter image description here
As you came to understand, merged cells are Excel's and VBA's worst nightmares! Avoid them (since they also make for terrible datastructures) if you can.
If you must use them and you need a function you can drag down, you'll need to make sure you create a mechanic that can skip certain rows. INDEX() is able to retrieve values with a 2nd parameter that tells the function which row you would like from a given array. If we make sure that this 2nd parameter has a steady incline we can still retrieve the correct values:
Formula in C1:
=INDEX(A:A,ROW()-1-MOD(ROW()-1,3)+1)&B1
After searching all over the internet, I didn't find the perfect solution, so I started learning VBA and I made this beautiful function, it detects if cells are merged or not and if so then it returns the top cell value.
Function Merg(CellRef As Range) As String
Dim MainCell As String
If CellRef.MergeCells Then
MainCell = Left(CellRef.MergeArea.Address, InStr(1,CellRef.MergeArea.Address, ":") - 1)
Else
MainCell = CellRef.Address
End If
Merg = Range(MainCell).Value
End Function
I don't know how to display the code properly on Stackoverflow. It's always a nightmare for me to understand the mechanics, you can visit my same thread on Microsoft Forum.

VBA loop preference

I am currently trying to optimize a VBA code with extreme execution time (56 hours and more on high end PC). The main problem is nested loops (up to 8) due to complicated iterative calculations and referencing ranges in formulas.
I have two questions:
1)
What loops are most preferred in VBA (based on their hardware strain for lack of better word)
2)
Is there a way to reference variable range of cells in a formula? For example in formula:
=AGGREGATE(15,6,SQRT((R2C10:R500000C10-RC[10])^2+(R2C11:R500000C11-RC[11])^2+(R2C12:R500000C12-RC[12])^2),1)
I am referencing relative cell: "R500000C10". There are two main issues: For one, the half milion cells might not capture all data - though in most cases there is less active cells than that, in same cases that might be an issue. Second, it takes forever to scan through so many cells (same reference is used in multiple of VLOOKUPs).
The first issue could be solved by referencing the whole column, but that makes the second problem worst.
I would like to reference it in a similar way that xlDown works:
Range().End(xlDown).Select
The problem there is I would need to reference it within the Active.Cell.FormulaR1C1. Is there a way to do that?
Thanks!
Well you wrote that you have a code with 8 loops and try to optimize it maybe you can edit and put part of that code, because your description is very general, however, with information that you put i speculate that about your point
1)it depend what do you want to do? because each "loop" have their own use for specifyc scenaries
2)there are tricks to do that but all depend what are you trying to do and why you want to use .formulaR1C1
again im speculating but you can try tu separate your loops in indenpendent function, and maybe you are putting a formula inside cells, and question is why? you can create functoins and Sub in your VBA code and do your "extrem execution" without use xtra "resours"

Excel nested if statement error how to fix?

trying to do a nested if :
=IF([Years of Service]>10,'Data Tables'!$B$11,"if([years of service]>5,'Data Tables'!$b$10)")
getting a spill error.
You don't indicate what you want to do and I'm not sure exactly what you really want to do.
But it seems your formula is within a Table. That being the case, formulas that output arrays, when placed in a Table will produce the #SPILL! error.
If, what you want to do, is to compare the Years of Service from the same row as the formula, then you need to refer just to that row, so as to not output an array.
eg:
=IF([#[Years of Service]]>10,'Data Tables'!$B$11,
IF([#[Years of Service]]>5,'Data Tables'!$B$10,
IF([#[Years of Service]]>1,'Data Tables'!$B$9,
'Data Tables'!$B$8)))
If you want something else, then you'll need to provide more detail.

Conditional standard deviation? STD.S with IF not working; trying to apply to data after using AVERAGEIFS with same conditions

(I am working with a Spanish interface, so please forgive the code in Spanish (the ; is a , in English, PROMEDIO.SI.CONJUNTO is AVERAGEIFS, INDICE is INDEX, FILA is ROW, DESVEST.M is STD.S, SI is IF, Y is AND).
I have look through all the threads about a "stvifs" (which Excel really should think about in the future!) and I am still unable to apply what I've learned to my data, even though it seems exactly like what I've seen! After successfully applying the following to my data:
=PROMEDIO.SI.CONJUNTO(E:E;A:A; INDICE(I:I; 2+(FILA(1:1)-1));D:D; 1;F:F; "BC")
I automatically got my column with "BC" and their means for each participant. (I have four conditions in total.) Now I want the SD for the SAME conditions. I tried applying this code as an array formula:
{=DESVEST.M(SI(Y((A:A)=INDICE(I:I; 2+(FILA(1:1)-1));(D:D)=1;(F:F) ="BC");E:E))}
I get a #DIV/0! error. I debugged the formula, and it is giving me FALSE as a result within the STD.S, hence the error. But what I don't understand is why it's not giving me an array with all the values in the column E that comply with the given conditions! The interesting thing is that when I apply the formula normally, it gives me STD.S(E:E) correctly, so I feel that this should work! I have done something similar with other data, but there weren't multiple conditions. Please help!
The formula would look something like this (in English) but not sure about ROW part and can't test it properly without some sample data:-
=STDEV.S(IF((A1:A10=INDEX(I1:I10, 2+ROW(1:1)-1))*(D1:D10=1)*(F1:F10 ="BC"),E1:E10))
Have limited it to 10 rows to make debugging easier with 'Evaluate Formula'.
This gives the stdev (sample) of the three shaded cells:-

Resources