ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   code for sort until cell equals... (https://www.excelbanter.com/excel-programming/426713-code-sort-until-cell-equals.html)

A[_3_]

code for sort until cell equals...
 
Hi -

I have two lists that I'm randomizing by sorting each one with a
column of =rand(). The lists both contain negative and positive words.
If a positive word is in list 1 and a negative in list 2, let's call
that 1pos-2neg. I need to have an even number of 1pos-2pos,
1pos-2neg, 1neg-2pos, and 1neg-2neg.

So I have a countif cell that determines the number of 1pos-2pos I
have and another countif cell that tells me how many 1pos-2neg I have
and so on. Then an "if" formula says all the countif cells have to be
the same and if they are it says "MATCH". Then I just keep sorting
until this cell says "MATCH."

Is there any excel code that basically says "After selecting columns M
and N, keep sorting column N until cell AA22 says "MATCH"?

Any help would be greatly appreciated.

A

A[_3_]

code for sort until cell equals...
 
Look like I figured it out.. pretty easy otherwise I wouldn't have
been able to get it

Thanks.

Sub Macro1()
Dim r As Range
Dim Rng As Range
Set r = Range("AA22")
Set Rng = Range("M:N")
Do
Rng.Sort _
Key1:=Range("N:N"), _
Order1:=xlAscending, _
Header:=xlYes, _
OrderCustom:=1, _
MatchCase:=False, _
Orientation:=xlTopToBottom
Loop Until r = "MATCH"
End Sub


All times are GMT +1. The time now is 03:43 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com