View Single Post
  #7   Report Post  
Posted to microsoft.public.excel.misc
Lars-Åke Aspelin[_2_] Lars-Åke Aspelin[_2_] is offline
external usenet poster
 
Posts: 913
Default Random number macro

I have only tested the macro I suggested in Excel 2007. There it seems
to work as expected. Don't know about other Excel versions though.

Lars-Åke

On Fri, 3 Jul 2009 14:00:01 -0700, Mike H
wrote:

Lars,

I have never been able to use RANDBETWEEN in the way you suggest and would
have to modify you macro thus to make it work, Can you really call it with
worksheetfunction? yes I do have all the relevent references set.

Sub victor_delta()
For i = 1 To ActiveSheet.Range("P1").Value
ActiveCell.Offset(i - 1) = Application.Run("ATPVBAEN.XLA!Randbetween",
1, Range("P2").Value)
Next i
End Sub

Mike

"Lars-Åke Aspelin" wrote:

On Fri, 3 Jul 2009 21:11:12 +0100, "Victor Delta"
wrote:


I would like to create an Excel macro which will put a series of random
integers (leaving values not the formulas) in cells in a column. It should
start in the currently selected cell and fill downwards until it has covered
the number of cells given by the number in, say, cell P1. The random
integers should be between 1 and the number in cell P2 (inclusive).

Can anyone help please?

Many thanks,

V


Try this macro:

Sub victor_delta()
For i = 1 To ActiveSheet.Range("P1").Value
ActiveCell.Offset(i - 1, 0).Value =
WorksheetFunction.RandBetween(1, ActiveSheet.Range("P2").Value)
Next i
End Sub

Hope this helps / Lars-Åke