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

Quick Sum
Select a range of cells. The total appears in bottom right of Excel screen. Right-click total to add Max, Min, Count, Average.

johnnyL

Well-known Member
Joined
Nov 7, 2011
Messages
1,339
Office Version
  1. 2013
  2. 2007
Platform
  1. Windows
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.
 

markhib

New Member
Joined
Apr 21, 2008
Messages
19
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
 

Forum statistics

Threads
1,141,572
Messages
5,707,156
Members
421,494
Latest member
Chiggi_897

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
Top