Excel如果满足条件,则在多列上查找并比较值

我有一个表代表客户的行,每个月,我在每行上添加一列代表他们作出的订单types(A,B或C)。

我需要确定每个订购A型(每个月)订单的客户,然后在接下来的几个月中,做出C型订单。

但是,如果从“A”到“C”types的订单(一个或多个月执行“C”)后,客户返回到“A”,我不需要识别他。

find“A”订单后,“B”订单无动于衷

给出的例子:

Client M1 M2 M3 M4 Identify 01 ABCC Yes 02 ABCA No 03 ACBA No 04 BBAC Yes 05 BACB Yes 06 CABB No 07 AAAC Yes 08 AAAA No 09 ACAC Yes 10 ACCA No 

等等。

我不知道我是否可以用一个简单的公式或使用VBA做到这一点。

编辑:由于每个月我添加一个新的列,公式或VBA应考虑所有可能性(如“ACCA”,“ACCCCA”等)。 还以客户端07,08,09和10为例。

先谢谢你。

JT

没有VBA一个简单的方法将是:(在F2中,然后复制下来)

 =IF(ISERROR(FIND("AC",SUBSTITUTE(B2&C2&D2&E2,"B",""))),"No",IF(ISERROR(FIND("ACA",SUBSTITUTE(B2&C2&D2&E2,"B",""))),"Yes","No")) 

作为“OnlyDoesWhatIAskedFor”-UDF把这个模块:

 Public Function getOrder(rng As Range) As String Dim runner As Variant, i As Long, comb As Variant comb = Array("A", "C", "A") getOrder = "No" For Each runner In rng.Value If runner = comb(i) Then If i = 2 Then getOrder = "No": Exit Function If i = 1 Then getOrder = "Yes" i = i + 1 ElseIf runner = comb(0) Then i = 1 ElseIf runner <> "B" Then i = 0 End If Next End Function 

然后在单元格输出(asuming F2并简单地复制下来)

 =getOrder(B2:E2) 

它只是检查范围内的交stream订单,而B将被忽略,ACA也输出“否”…

编辑

如果只有最后一个AC / ACA计数,那么你将需要这样的事情:(在模块中)

 Public Function getResult(rng As Range) As String Dim a As Variant, b As String 'Col W - changes the cells to one long string / "B" will be left out For Each a In rng.Value If a <> "B" Then b = b & a Next 'Col X - skips xxACAxx to Axx till no ACA is left While InStr(b, "ACA") b = Mid(b, InStr(b, "ACA") + 2) Wend '<~~~ add from here for ACCA = "No" (ACCAC will still be "YES") While InStr(b, "ACCA") b = Mid(b, InStr(b, "ACCA") + 2) Wend '<~~~ add till here for ACCA = "No" (ACCAC will still be "YES") 'Col Y - Checks if an AC is found in the leftover 'Col Z - if the check is >0 then it will be YES else No If InStr(b, "AC") Then getResult = "Yes" Else getResult = "No" End Function 

您可以在下面的图片中看到它所做的每一步: 在这里输入图像说明

Interesting Posts