Loop Macro until cell =0

markhib

New Member
Joined
Apr 21, 2008
Messages
19
Hi All, I have a macro which creates a random number against each row of data then and sorts smallest to largest. this then populates an error report. i want to keep running the macro over and over until i get no errors.

My current macro is

Sub runrand2()
'
' runrand2 Macro
'

'
Calculate
Range("A2").Select
Range(Selection, Selection.End(xlDown)).Select
Range(Selection, Selection.End(xlToRight)).Select
ActiveWorkbook.Worksheets("Sheet3").Sort.SortFields.Clear
ActiveWorkbook.Worksheets("Sheet3").Sort.SortFields.Add2 Key:=Range("E2:E109" _
), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
With ActiveWorkbook.Worksheets("Sheet3").Sort
.SetRange Range("A1:E109")
.Header = xlYes
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
End Sub

How do i put a loop on it so it runs over and over until cell J2 =0

Many Thanks

MH
 

Excel Facts

Does the VLOOKUP table have to be sorted?
No! when you are using an exact match, the VLOOKUP table can be in any order. Best-selling items at the top is actually the best.
It looks like you have failed to provide some code that is needed to assist you. For starters, the randomization code, code that involves J2, error report, etc. The code you provided appears to be just sorting code.
 
Upvote 0
It looks like you have failed to provide some code that is needed to assist you. For starters, the randomization code, code that involves J2, error report, etc. The code you provided appears to be just sorting code.
the rest of it is just done outside VB. i have used =rand() to create my random numbers in the sheet and then a countif to count the errors , resulting in a number of errors in J2. each time i run the macro it just creates new random numbers and re-sorts the list, if the criteria is not met, i get an error. Just want the macro to loop. Cheers MH
 
Upvote 0

Forum statistics

Threads
1,215,038
Messages
6,122,798
Members
449,095
Latest member
m_smith_solihull

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top