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
Bookmarks