вы можете предложить мне рутина - алгоритм в VBA, который может принимать следующие строки в качестве входных данных: «A14, A22, A23, A24, A25, A33» и превратить его к этому: «A14, A22 - A25, A33» ?Скрыть последовательные значения в VBA
Спасибо
EDIT: Благодаря @omegastripes
Sub Test()
Dim strText, strRes, strTail, i
Dim comma As String: comma = ", "
Dim dash As String: dash = "-"
Dim delimiter As String
Dim counter As Integer
strText = "A14, A22, A23, A24, A25, A26, A33, A34"
strRes = ""
strTail = ""
With CreateObject("VBScript.RegExp")
.Global = True
.Pattern = "([a-zA-Z])(\d+)"
With .Execute(strText)
strRes = .Item(0).Value
For i = 1 To .Count - 1
If (.Item(i).SubMatches(0) = .Item(i - 1).SubMatches(0)) And (.Item(i).SubMatches(1) - .Item(i - 1).SubMatches(1) = 1) Then
counter = counter + 1
If counter > 1 Then
delimiter = dash
Else
delimiter = comma
End If
strTail = delimiter & .Item(i).SubMatches(0) & .Item(i).SubMatches(1)
Else
Debug.Print "strRes: " & strRes & ", " & "strTail: " & strTail & ", " & .Item(i).SubMatches(1)
strRes = strRes & strTail & ", " & .Item(i).SubMatches(0) & .Item(i).SubMatches(1)
strTail = ""
counter = 0
End If
Next
strRes = strRes & strTail
End With
End With
MsgBox strText & vbCrLf & strRes
End Sub
Вы можете попробовать регулярные выражения и петли спички, сравнивая каждый с предыдущим пропустить соседние элементы в пределах интервалов. – omegastripes