, , - . , , , , .
Private Sub Combine()
Dim i, j, m, n As Integer
Dim LookStart, SvaeStart As Range
'Assume the data stored in column A, Cells A2:A9
'Put the results in Column B,starting with cell B2
Set LookStart = Range("A2")
Set SaveStart = Range("B2")
i = 0
j = FindEnd(LookStart)
m = 0
Do
n = FindNext(LookStart.Offset(m, 0))
SaveStart.Offset(i, 0).Value = LookStart.Offset(m, 0).Value
If n <> 0 Then
SaveStart.Offset(i, 0).Value = SaveStart.Offset(i, 0).Value & _
" -- " & LookStart.Offset(m + n, 0).Value
End If
m = m + n + 1
i = i + 1
Loop While m <= j
End Sub
Private Function FindEnd(ByVal start As Range) As Integer
FindEnd = Range("A1").Offset(Cells.Rows.Count - 1, _
start.Column - 1).End(xlUp).Row - start.Row
End Function
Private Function FindNext(ByVal start As Range) As Integer
Dim i, j, flag, CurrentNum, LastNum As Integer
Dim CurrentText As String
i = 0
j = FindEnd(start)
flag = 0
Do
CurrentText = start.Offset(i, 0).Text
If i <> 0 Then
If LastNum + 1 <> Left(CurrentText, Application.WorksheetFunction.Find("-", _
CurrentText) - 1) * 100 + Right(CurrentText, 2) Then flag = 1
End If
LastNum = Left(CurrentText, Application.WorksheetFunction.Find("-", _
CurrentText) - 1) * 100 + Right(CurrentText, 2)
i = i + 1
Loop While flag = 0 And i <= j
If flag = 0 Then FindNext = i - 1
If flag = 1 Then FindNext = i - 2
End Function
:
A | B
2-16 | 2-16 - 2-18
2-17 | 2-30
2-18 | 2-32 - 2-34
2-30 | 2-56 - 2-58
2-32 | 2-60
2-33
2-34
2-56
2-57
2-58
2-60
- ? !
, !