Results 1 to 2 of 2

Thread: help with something quick and easy

  1. #1

    help with something quick and easy



    Register for a FREE account, and/
    or Log in to avoid these ads!

    So I found a sorting property to arrange numbers numerically but I have messed up something simple in the code

    here is the website I got it from any way i could get a close fix


    Sort Numbers in Excel VBA - Easy Excel Macros



    Here is the code I got from is im missing something simple any ideas thanks guys

    Code:
    Sub start()
    Code:
    Dim i As Integer, j As Integer, temp As Integer, rng As Range
    
        Set rng = Range("A1").CurrentRegion
        For i = 1 To rng.Count
            For j = i + 1 To rng.Count
                If rng.Cells(j) < rng.Cells(i) Then
    
                End If
    
                'swap numbers
                temp = rng.Cells(i)
                rng.Cells(i) = rng.Cells(j)
                rng.Cells(j) = temp
    
            Next j
    
        Next i
    
    End sub
    Last edited by Bob Phillips; 2014-06-20 at 09:19 AM. Reason: Added VBA tags

  2. #2
    That article was badly written, it didn't explain that you needed to insert the swap code betweenm the If ... EndIf

    Code:
    Sub start()
    Dim i As Integer, j As Integer, temp As Integer, rng As Range
    
    
        Set rng = Range("A1").CurrentRegion
        For i = 1 To rng.Count
            For j = i + 1 To rng.Count
                If rng.Cells(j) < rng.Cells(i) Then
    
    
                    'swap numbers
                    temp = rng.Cells(i)
                    rng.Cells(i) = rng.Cells(j)
                    rng.Cells(j) = temp
                End If
            Next j
        Next i
    End Sub

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •