For my own amusement I am trying to automate a project from work to learn more about excel vba. For the primary tab of data, I have an import function that drags in the relevant columns from another sheet for columns A through J. After that, there are a bunch of columns already set up to manipulate the the data being imported.
One of the calculation columns is supposed to return a basic 0/1 flag if the related company has been a client for >20 years. However, it ended up being a very slow UDF, so I wrapped it in an If statement to check if any other flags are false first so I can skip the slow calculation if the claim is already being eliminated. It worked fine before I went back to tweaking the import macro. Here is the function:
=IF( Q2*O2*N2 = 0, 0, IF(CompanyYears(J2, End_of_Claim_Period, Analysis_Width) >= Valid_Co_Years, 1, 0))
So now after the data import the only two results the column gives are 0 and #VALUE!. However, the 'evaluate function' step through confused me more. Turns out that for every value error, the 3 flags from columns Q/O/N are 1. So first the evaluate looks up and multiplies those 3 flags, gets 1=0 -> FALSE. The next thing it does is resolve what the named range End_of_Claim_Period points to. While it successfully changes it to a cell address, the outer IF statement's value_if_true changes from 0 to #N/A! at the same time. The inner if statement continues just fine to a result of 0 or 1, and finally the statement
=IF(FALSE, #N/A!, 1)
or
=IF(FALSE, #N/A!, 0)
gets evaluated to #VALUE!.
Also, if I try to filter that column to see only the rows with a #VALUE! response, it correctly reevaluates them to the appropriate 0/1 values. I tried having the vba code filter then unfilter the row automatically but that leaves the errors in place still.
Aucun commentaire:
Enregistrer un commentaire