Results 1 to 5 of 5

Need help identifying a value range for ending a Loop Until

Threaded View

  1. #1
    Registered User
    Join Date
    06-01-2013
    Location
    boston, ma
    MS-Off Ver
    Excel 2003
    Posts
    3

    Question Need help identifying a value range for ending a Loop Until

    Hi. I have virtually no programming experience. I used the Macro Recorder to produce this code to generate a column of random numbers and then sort several columns of data by those numbers, effectively randomizing them. I poked around some discussion boards and was able to learn how to set up a rudimentary Do… Loop Until so the macro will run until a cell auto-populated by a selection of the data being randomized reaches a criterion value.

    The macro does run OK, but my problem is I need to be able to define a range this is at the same time both above one value and below another value (e.g., both > -0.0055 and < 0.0055), and right now I can only do one or the other (e.g., either > -0.0055 or < 0.0055). I’d also like to know how to define a loop stopping criterion based on values from two different cells, or on ranges from two different cells.

    This should be an easy fix for someone with some experience with VBA. Thanks in advance. Here is my code:

        Do
        ActiveCell.FormulaR1C1 = "=RAND()"
        Range("M2").Select
        Range("M2:M429").Select
        Selection.FillDown
        Range("A2:M429").Select
        Range("M2").Activate
        Selection.Sort Key1:=Range("M2"), Order1:=xlAscending, Header:=xlNo, _
            OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom
        Range("M2:M429").Select
        Selection.End(xlDown).Select
        Range("M429").Select
        Loop Until Range("L433").Value > -0.0055
    End Sub
    Last edited by JBeaucaire; 06-04-2013 at 07:20 PM. Reason: Added CODE tags and corrected title, as per Forum Rules. Take a moment to read the Forum Rules in the menu bar above. Thank

Thread Information

Users Browsing this Thread

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

Tags for this Thread

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