View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.programming
Craig Craig is offline
external usenet poster
 
Posts: 208
Default Macro automatic execution x times

I appreciate you taking the time to generate the code. Unfortunately, I am
not a VBA programmer so I really don't know what to do with it. I was hoping
I could automate the process with standard Excel functions. I appreciate
your efforts! I think I am doomed to just manually run my macro and
copy/paste special/values into the result area. A bit tedious for a 50 or
100 set run, but then again ....

Thank you!!

"merjet" wrote:

Something like this calls for VBA.

Sub Macro1()
Dim iCt As Integer
Dim iCt2 As Integer
Dim iMax As Integer
Dim ws As Worksheet

Set ws = Sheets("Sheet1")
iMax = InputBox("Enter number of iterations.")

ws.Range("A11:D500").Clear
For iCt = 1 To iMax
For iCt2 = 1 To 4
ws.Cells(iCt2, 1) = Rnd
Next iCt2
ws.Range("A1:B4").Sort Key1:=Range("A1"), _
Order1:=xlAscending, Header:=xlGuess, _
OrderCustom:=1, MatchCase:=False, _
Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal
ws.Cells(10 + iCt, 1) = "Result " & iCt
ws.Cells(10 + iCt, 3) = ws.Cells(5, 3)
ws.Cells(10 + iCt, 4) = ws.Cells(5, 4)
Next iCt
ws.Cells(10 + iMax + 1, 1) = "Averages"
ws.Range("C" & 10 + iMax + 1 & ":D" & 10 + iMax + 1) _
.FormulaR1C1 = "=AVERAGE(R[" & -iMax & "]C:R[-1]C)"

End Sub


Hth,
Merjet