Here you go:

```
Dim numbers() As Integer
Dim numberss() As String
Dim ranges() As String
Dim list As String = "1,2,3,4,6,7,8,9,10,11,12,15,19,21,22"
Dim startAt, maxPosition, pos, offset, gap As Integer
ReDim ranges(0)
ranges(0) = ""
numberss = list.Split(",")
startAt = 0
maxPosition = numberss.Length - 1
ReDim numbers(maxPosition)
For pos = 0 To maxPosition
numbers(pos) = CInt(numberss(pos))
Next
Array.Sort(numbers)
For pos = 0 To maxPosition
If pos < maxPosition Then offset = 1 Else offset = 0
gap = numbers(pos + offset) - numbers(pos)
If gap > 1 Or pos = maxPosition Then
If ranges(0) <> "" Then Array.Resize(ranges, ranges.Length + 1)
If startAt < pos Then
ranges(ranges.Length - 1) = CStr(numbers(startAt)) & "-" & CStr(numbers(pos))
Else
ranges(ranges.Length - 1) = CStr(numbers(pos))
End If
startAt = pos + 1
End If
Next
MsgBox(String.Join(",", ranges))
```