Speed Code execution

ISY

Active Member
Joined
Nov 16, 2009
Messages
430
Office Version
  1. 365
Platform
  1. Windows
HELP!!! "Speed Code execution"

I'm looking for a code to load the values ​​into an array of two columns ("A" & "B") , and sort them in ascending order to insert them into a Listwiew.

Example Date the present value in column A = 40470
Now in this example value in column B = 16,3

Thanks in advance
 

Excel Facts

Wildcard in VLOOKUP
Use =VLOOKUP("Apple*" to find apple, Apple, or applesauce
Hallo
I'm looking for an alternative to the following code to rewrite some guidance Thanks
The code works but uses sort a 1d array so that to use the values ​​I have to then take the first 5 characters to the left etc ...

In a Form:
Code:
Private Sub UserForm_Initialize()
    ReDim Arr1(1 To D)
    For i = 4 To D
        Arr1(i) = Foglio5.Cells(i, 1)
    Next i
    Set AF = Application.WorksheetFunction
    Fineriga = AF.Max(Cells(Rows.Count, 1).End(xlUp).Row, _
    Cells(Rows.Count, 2).End(xlUp).Row, Cells(Rows.Count, 3).End(xlUp).Row)
    ReDim arr10(1 To 1)
    Num = CDbl((Date))
    For Lval = 11 To Fineriga
        V = V + 1
        arr10(V) = CDbl(Cells(Lval, 3)) & (10000 + CDbl(Cells(Lval, 4) * 100))
        ReDim Preserve arr10(1 To V + 1)
    Next
    Array1DSort arr10
    With ListView1
        [COLOR=Red]'[/COLOR][COLOR=Red]the code obtained here, it is read![/COLOR]
        [COLOR=Red]'Right(arr10(ciclo), 4)
        'Left(arr10(Orex), 5)[/COLOR]
     End With
    Set AF = Nothing
End Sub
---------------------------------------------------------------
In un modulo:
Code:
'The following code can be used to rapdily sort a 1d array.

'Purpose   :    Sorts a 1D array.
'Inputs    :    avValues. The array to sort
'               [lLowerBound]               The lLowerBound of Array. NOT REQUIRED (USED IN RECURSIVE LOOP)
'               [lUpperBound]               The lUpperBound of Array. NOT REQUIRED (USED IN RECURSIVE LOOP)
'               [bSortDescending ]          If True sorts the array in descending order. Defaults to ascending.
'Outputs   :    avValues is sorted.
'Notes     :    The optional parameters are not required to be passed in.
'               They are only required for the subsequent recursive calls.
'               This type of sorting is much faster than "Bubble Sorting", especially
'               if your items are order randomly.


Sub Array1DSort(ByRef avValues As Variant, Optional lLowerBound As Long, Optional lUpperBound As Long, Optional ByVal bSortDescending As Boolean = False)
    Dim lTestLower As Long, lTestUpper As Long, vThisItem As Variant, vThisValue   As Variant
    
    If lLowerBound = 0 Then
        lLowerBound = LBound(avValues)
    End If
    If lUpperBound = 0 Then
        lUpperBound = UBound(avValues)
    End If
    
    lTestLower = lLowerBound
    lTestUpper = lUpperBound
    
    vThisItem = avValues((lLowerBound + lUpperBound) / 2)
    
    If bSortDescending Then
        Do While (lTestLower <= lTestUpper)
            Do While (avValues(lTestLower) > vThisItem And lTestLower < lUpperBound)
                lTestLower = lTestLower + 1
            Loop
            Do While (vThisItem > avValues(lTestUpper) And lTestUpper > lLowerBound)
                lTestUpper = lTestUpper - 1
            Loop
            If (lTestLower <= lTestUpper) Then
                vThisValue = avValues(lTestLower)
                avValues(lTestLower) = avValues(lTestUpper)
                avValues(lTestUpper) = vThisValue
                lTestLower = lTestLower + 1
                lTestUpper = lTestUpper - 1
            End If
        Loop
    Else
        Do While (lTestLower <= lTestUpper)
            Do While (avValues(lTestLower) < vThisItem And lTestLower < lUpperBound)
                lTestLower = lTestLower + 1
            Loop
            Do While (vThisItem < avValues(lTestUpper) And lTestUpper > lLowerBound)
                lTestUpper = lTestUpper - 1
            Loop
            If (lTestLower <= lTestUpper) Then
                vThisValue = avValues(lTestLower)
                avValues(lTestLower) = avValues(lTestUpper)
                avValues(lTestUpper) = vThisValue
                lTestLower = lTestLower + 1
                lTestUpper = lTestUpper - 1
            End If
        Loop
    End If
    
    If (lLowerBound < lTestUpper) Then
        Array1DSort avValues, lLowerBound, lTestUpper, bSortDescending
    End If
    
    If (lTestLower < lUpperBound) Then
        Array1DSort avValues, lTestLower, lUpperBound, bSortDescending
    End If
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,506
Messages
6,179,159
Members
452,892
Latest member
yadavagiri

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top