公式比较一个列行中的string数是否相等

我在Excel中有一个名为“职位”的专栏。 列可以有这样的string数字

位置

1-5

1-7

1-7

1-8

1-89

2-1

2-12

2-2

2-3

….. NN …第一个数字是参考页码和第二个数字,即在“ – ”参考页面位置之后。

该页面从左到右分为9个位置,就像这样:

1 2 3

4 5 6

7 8 9

所以当你在位置栏中有1-8号码时,这意味着:

第1页

1 2 3

4 5 6

7(8)9

当你在位置列中有2-12个数字时,这意味着:

第2页

(1)(2)3

4 5 6

7 8 9

现在就是这样devise的,但是我想要修改的只是位置列,当我有一组像前面提到的位置

位置

1-5

1-7

1-7

1-8

1-89

2-1

2-12

2-2

2-3

…..

那么我需要一个公式来以某种方式通知我1-8位和1-89位置会重叠,而位置2-1,2-12和2-2也会重叠。 当然,位置1-7和位置1-7将完全重叠,因此这也应通知用户。 我怎么能这样做?

由于OP添加了VBA标签; 请尝试这个程序。 它将相应的3 pieces一个Position与列表中的所有其他Positions进行比较。 它假定Positions列表从B2开始,并在C列中列出比较结果。

 'These Options declaration always go at the top of the module, class, etc. Option Explicit Option Base 1 Sub Get_Overlap() Const kFlag As String = "Overlapping" 'Change as required Dim rData As Range, aData As Variant, aResults() As String, sResult As String Dim lA As Long, sAvalue As String, iAp As Integer, bA1 As Byte, bA2 As Byte Dim lB As Long, sBvalue As String, iBp As Integer, bB1 As Byte, bB2 As Byte Rem Sets Data Range & Arrays With ThisWorkbook.Sheets("TEST").Columns("B") 'Change as required Set rData = Range(.Cells(2), .Cells(Rows.Count).End(xlUp)) End With aData = rData.Value2 aData = WorksheetFunction.Transpose(aData) rData.Offset(0, 1).ClearContents ReDim Preserve aResults(UBound(aData)) For lA = 1 To UBound(aData) Rem Initialize & Set Item A Values sAvalue = Empty: sAvalue = aData(lA) iAp = 0: iAp = Left(sAvalue, 1) bA1 = 0: bA1 = Mid(sAvalue, 3, 1) On Error Resume Next bA2 = 0: bA2 = Mid(sAvalue, 4, 1) On Error GoTo 0 For lB = lA + 1 To UBound(aData) Rem Initialize & Set Item B Values sBvalue = Empty: sBvalue = aData(lB) iBp = 0: iBp = Left(sBvalue, 1) bB1 = 0: bB1 = Mid(sBvalue, 3, 1) On Error Resume Next bB2 = 0: bB2 = Mid(sBvalue, 4, 1) On Error GoTo 0 Rem Initialize Comparison Result sResult = Empty Rem Compare Items & Values Select Case True Case sAvalue = sBvalue sResult = kFlag Case iAp = iBp Select Case True Case bA2 = 0 And bB2 = 0 If (bA1 = bB1) Then sResult = kFlag Case bA2 = 0 If bA1 >= bB1 And bA1 <= bB2 Then sResult = kFlag Case bB2 = 0 If bB1 >= bA1 And bB1 <= bA2 Then sResult = kFlag Case Else If bA1 >= bB1 And bA1 <= bB2 Then sResult = kFlag ElseIf bA2 >= bB1 And bA2 <= bB2 Then sResult = kFlag ElseIf bB1 >= bA1 And bB1 <= bA2 Then sResult = kFlag ElseIf bB2 >= bA1 And bB2 <= bA2 Then sResult = kFlag End If End Select: End Select Rem Add Results into Array If sResult <> Empty Then aResults(lA) = sResult aResults(lB) = sResult End If Next: Next Rem Enter Comparison Results 'Results will be posted one column to the right of where the List 'This is done by the use of "rData.Offset(0,1)" rData.Offset(0, 1).Value = WorksheetFunction.Transpose(aResults) End Sub 

build议阅读以下页面,以深入了解所使用的资源:

选项关键字 , variables和常量 , 与语句 , 范围对象(Excel) , 工作表函数对象(Excel) , 对于…下一个语句 , select个案语句 , 如果…那么…其他语句 , 在错误语句 , 范围。偏移属性(Excel)