У меня есть столбец (A), имеющий значения
| 3, 4, 5|
|2, 4, 5|
|4, 5|
|2, 3|
|5|
|4|
|3|
и все другие возможные комбинации 3,2 и 1 балл из набора {2,3,4,5}. Я хочу всю возможную комбинацию между этими элементами, чтобы в наборах не было повторения чисел, т.е. |3, 4, 5|
можно комбинировать только с |2|
или |3, 4|
, можно комбинировать только с |2, 5|
или |2|
и |5|
Dim lRowCount As Long
Dim temp As String, s As String
Dim arrLength As Long
Dim hasElement As Boolean
Dim plans() As String, currentPlan() As String
Dim locationCount As Long
Dim currentRoutes As String
Dim line As Long
Worksheets("Sheet1").Activate
Application.ActiveSheet.UsedRange
lRowCount = ActiveSheet.UsedRange.Rows.Count
locationCount = -1
line = 2
Debug.Print ("*********")
For K = 2 To lRowCount - 1
currentRoutes = ""
For i = K To lRowCount
s = ActiveSheet.Cells(i, 1)
Do
temp = s
s = Replace(s, " ", "")
Loop Until temp = s
currentPlan = Split(Trim(s), ",")
arrLength = UBound(currentPlan) - LBound(currentPlan) + 1
hasElement = False
If Len(Join(plans)) > 0 Then
For j = 0 To arrLength - 1
pos = Application.Match(currentPlan(j), plans, False)
If Not IsError(pos) Then
hasElement = True
Exit For
End If
Next j
End If
If Not hasElement Then
currentRoutes = currentRoutes & (Join(currentPlan, ",")) & " "
If Len(Join(plans)) > 0 Then
plans = Split(Join(plans, ",") & "," & Join(currentPlan, ","), ",")
Else
plans = currentPlan
End If
End If
Next i
If locationCount < 0 Then
locationCount = UBound(plans) - LBound(plans) + 1
End If
If (UBound(plans) - LBound(plans) + 1) < locationCount Then
Debug.Print ("Invalid selection")
Else
Debug.Print (Trim(currentRoutes))
Worksheets("Sheet1").Cells(line, 11) = currentRoutes
line = line + 1
End If
Erase plans
Debug.Print ("*********")
Next K
В настоящее время проблема заключается в том, что если выбрана комбинация |3,4|
, она проверяет только одну следующую возможную комбинацию, т. Е. Для нее требуется |3,4|
& |2,5|
, но не проверяется |2|
& |5|
. Пожалуйста, помогите мне решить эту проблему.