| Цитата |
|---|
| написал: расположить их по возрастанию |
| Код |
|---|
Function ВЫВЕСТИДАННЫЕ(диаметры_и_высоты As Range) As String
Dim arr As Variant
arr = диаметры_и_высоты.Rows(1).Value
Dim xa As Long, dic As Object
Set dic = CreateObject("Scripting.Dictionary")
For xa = 1 To UBound(arr, 2) Step 2
If arr(1, xa) <> "" Then dic(arr(1, xa)) = Empty
Next
If dic.Count > 0 Then
Dim brr As Variant
brr = dic.Keys()
Quicksort brr, 0, UBound(brr)
ВЫВЕСТИДАННЫЕ = Join(brr, " - ")
End If
End Function
Private Sub Quicksort(vArray As Variant, arrLbound As Long, arrUbound As Long)
'Sorts a one-dimensional VBA array from smallest to largest
'using a very fast quicksort algorithm variant.
Dim pivotVal As Variant
Dim vSwap As Variant
Dim tmpLow As Long
Dim tmpHi As Long
tmpLow = arrLbound
tmpHi = arrUbound
pivotVal = vArray((arrLbound + arrUbound) \ 2)
While (tmpLow <= tmpHi) 'divide
While (vArray(tmpLow) < pivotVal And tmpLow < arrUbound)
tmpLow = tmpLow + 1
Wend
While (pivotVal < vArray(tmpHi) And tmpHi > arrLbound)
tmpHi = tmpHi - 1
Wend
If (tmpLow <= tmpHi) Then
vSwap = vArray(tmpLow)
vArray(tmpLow) = vArray(tmpHi)
vArray(tmpHi) = vSwap
tmpLow = tmpLow + 1
tmpHi = tmpHi - 1
End If
Wend
If (arrLbound < tmpHi) Then Quicksort vArray, arrLbound, tmpHi 'conquer
If (tmpLow < arrUbound) Then Quicksort vArray, tmpLow, arrUbound 'conquer
End Sub
|