Results 1 to 3 of 3

Extension to existing code. . .very urgent

Threaded View

  1. #1
    Registered User
    Join Date
    05-29-2013
    Location
    Silchar, Assam,India
    MS-Off Ver
    Excel 2007
    Posts
    13

    Question Extension to existing code. . .very urgent

    Hi,

    I have the following code which allows me to randomly choose numbers( as much required )

    from a set of data available in column A.

    ==============================================================

    Sub test()
        Dim myMax As Long, a, i As Long
        myMax = [c2].Value
        If myMax < 1 Then Exit Sub
        With Cells(1).CurrentRegion.Offset(1)
            .Columns("b").ClearContents
            a = .Resize(, 2).Value
            Randomize:
            For i = 1 To UBound(a, 1) - 1
                a(i, 2) = Rnd
            Next
            VSortM a, 1, UBound(a, 1) - 1, 2
            .Columns(2).Resize(myMax).Value = a
        End With
        Call Choosen
        
    End Sub
    
    Private Sub VSortM(ary, LB, UB, ref)
        Dim M As Variant, i As Long, ii As Long, iii As Long, temp
        i = UB: ii = LB
        M = ary(Int((LB + UB) / 2), ref)
        Do While ii <= i
            Do While ary(ii, ref) < M: ii = ii + 1: Loop
            Do While ary(i, ref) > M: i = i - 1: Loop
            If ii <= i Then
                For iii = LBound(ary, 2) To UBound(ary, 2)
                    temp = ary(ii, iii): ary(ii, iii) = ary(i, iii)
                    ary(i, iii) = temp
                Next
                ii = ii + 1: i = i - 1
             End If
        Loop
        If LB < i Then VSortM ary, LB, i, ref
        If ii < UB Then VSortM ary, ii, UB, ref
    End Sub
    ==============================================================

    Now, I want an extension to this code. What I want is that the extended code should first

    search for the number 1234567899 in column A and if found should place the same in the

    result first & then pick rest of the numbers.If the number(1234567899) is not there in

    column A then the existing code should straight way get execute skipping the search for

    number 1234567899.Hope, I am able to make you understand what I wanted.
    Attached Files Attached Files
    Last edited by arlu1201; 05-30-2013 at 08:51 AM. Reason: Use code tags in future.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1