I have been racking my brain around the best way to check if the cell value in three cells are exactly the same. However, the tricky part is that any one of these three cells can be blank. I have not found a simple solution that does not require a dozen IF and EXACT functions within the cell's formula. I've tried some user defined functions to hopefully reduce the complexity of the cell's formula, but I'm not sure what the best approach is.
I am working on a excel sheet that allows the users to import excel files on to the workbook (see screenshot below). There is code that parses through the imported file's filename and pastes the "E1#" to the appropriate cell (we will call that cell A2. Cell A1 is where the file's directory path is displayed. The "E1#" number for the Quant file goes in A2, the "E1#" number for the Sequence File goes in A4 (file dir goes in A3), and the Order Details "E1#" goes in A6. Each file is optional, so the "E1#"-cells (A2, A4, A6) may or may not have a numeral value in them. The grey cell (A7) should display "Match" because cells A2 and A6 have matching E1# numbers of "1234". If only one cell had a numeral value and the other two E1#-cells were blank, then the grey cell would remain blank. If more than one of the E1# cells are filled with a number and if the numbers do not match each other, then the grey cell displays "Mismatch".
Side note: When I originally created this excel sheet. The users said they only needed Quant and Sequence File fields. So creating a cell formula (within the grey cell) for checking that two cells (A2 and A4) are matching was fairly simple. A couple of IF, ISBLANK and EXACT statements made it work great. But now I had to add the third file field ("Order Details") to the excel sheet. And now I can't figure out how to make the "match/mismatch" checking work now. Is there a better algorithm or code practice that I could be taking? Any advice would be greatly appreciated.
I've tried making a very long cell formula with IF, ISBLANK, and EXACT functions. But the cell formula becomes too complicated to debug and read. I've created a couple user defined functions but I'm still struggling to make a working and cohesive cell formula with it. (Below) my UDF is used in the cell formula with the EXACT function. InterfaceComp_str returns the E1# number or blank.
Public Function InterfaceComp_str(c1 As String, c2 As String) As String
If Len(c1) < 1 Then
InterfaceComp_str = c2
End If
If Len(c2) < 1 Then
InterfaceComp_str = c1
End If
If Not IsEmpty(c1) And Not IsEmpty(c2) Then
If InStr(c1, c2) <> 0 And Len(c1) = Len(c2) Then
InterfaceComp_str = c2
End If
End If
End Function`
Here is an example of the cell formula in the grey cell (A7):
=IF(EXACT(InterfaceComp_str(A2,A4),InterfaceComp_str(A4,A6)),"Match", "Mismatch")
But there are a lot of issues with this cell formula. I'm not sure if my UDF is the correct approach to tackle this problem.