Consulting

Results 1 to 19 of 19

Thread: Random

  1. #1
    VBAX Tutor
    Joined
    Dec 2009
    Posts
    295
    Location

    Random

    hi

    how can i get random numbers
    between 34.01 and 33.99 i need at least 25 numbers


    thanks

  2. #2
    Moderator VBAX Guru Aussiebear's Avatar
    Joined
    Dec 2005
    Location
    Queensland
    Posts
    4,999
    Location
    lookup RandBetween in Excel Help. This will give you a start until someone comes along.
    Remember To Do the Following....
    Use [Code].... [/Code] tags when posting code to the thread.
    Mark your thread as Solved if satisfied by using the Thread Tools options.
    If posting the same issue to another forum please show the link

  3. #3
    Knowledge Base Approver VBAX Guru GTO's Avatar
    Joined
    Sep 2008
    Posts
    3,368
    Location
    Try:

    =RAND()*(34.01-33.99)+33.99

    ...entered as an array.

    Good reading: http://www.cpearson.com/excel/randomNumbers.aspx

  4. #4
    VBAX Tutor
    Joined
    Dec 2009
    Posts
    295
    Location
    thanks

  5. #5
    VBAX Tutor
    Joined
    Dec 2009
    Posts
    295
    Location

    random macro

    hi
    i need some help with a macro.
    in sheet1 cell b1 the user enters the upper number in cell b2 the user enters the lower number and in cell b3 the user enters the number of how much random numbers needed
    the macro that i need for random between two numbers



    thanks for the help

  6. #6
    Knowledge Base Approver VBAX Guru GTO's Avatar
    Joined
    Sep 2008
    Posts
    3,368
    Location
    Oleg,

    Could you stick with your original thread on this?

    Mark

  7. #7
    VBAX Tutor
    Joined
    Dec 2009
    Posts
    295
    Location
    Tell me how and I will do this

  8. #8
    Administrator
    VP-Knowledge Base
    VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    Threads merged.
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  9. #9
    Hi guy
    try this !!

  10. #10
    Administrator
    VP-Knowledge Base VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    Hi Yasser,
    Try to avoid looping, it slows down your code
    [VBA]
    Sub Test()
    Dim rng1, cell, R1, R2 As Range
    Dim cel As Range
    Set cel = Selection
    Set R1 = ActiveSheet.Range("B1")
    Set R2 = ActiveSheet.Range("B2")
    Set R3 = ActiveSheet.Range("B3")
    Set rng1 = Range(Cells(1, "C"), Cells(R3, "C"))
    Application.ScreenUpdating = False
    Columns("C:C").ClearContents
    With rng1
    .Formula = "=Randbetween(" & R1 & "," & R2 & ")"
    .Copy
    .PasteSpecial Paste:=xlPasteValues
    End With
    cel.Select
    Application.CutCopyMode = False
    Application.ScreenUpdating = True
    End Sub

    [/VBA]
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  11. #11
    VBAX Tutor
    Joined
    Dec 2009
    Posts
    295
    Location
    hi

    how can i get it to work?

  12. #12
    VBAX Tutor
    Joined
    Dec 2009
    Posts
    295
    Location
    hi
    i can not use numbers with decimal places for example
    i need 20 numbers between 34.01 and 33.99

    this not working
    thanks for your help

  13. #13
    Administrator
    VP-Knowledge Base VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    Quote Originally Posted by oleg_v
    hi
    i can not use numbers with decimal places for example
    i need 20 numbers between 34.01 and 33.99
    There is only one whole number, I believe, between 34.01 and 33.99. Can you post a list which might be randomly generated which meets your criteria?
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  14. #14
    VBAX Tutor
    Joined
    Dec 2009
    Posts
    295
    Location
    hi
    i column E you can see the results that was generated by the formula:
    =RAND()*(34.01-33.99)+33.99

  15. #15
    Administrator
    VP-Knowledge Base VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    That is what you asked for in Post 1. What answer are you expecting, as per my last question?
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  16. #16
    VBAX Tutor
    Joined
    Dec 2009
    Posts
    295
    Location
    i need a macro to do this.
    for the user that will enter the desirable borders and by
    pressing the button he will get the results.

    thanks

  17. #17
    Administrator
    VP-Knowledge Base VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    I cannot assist if you do not answer the questions I have asked.
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  18. #18
    Try this
    I think the solution of array formulas is the best
    Generally here's the code
    Sub Test()
        Dim rng1, cell, R1, R2 As Range
        Dim cel As Range
        Set cel = Selection
        Set R1 = ActiveSheet.Range("B1")
        Set R2 = ActiveSheet.Range("B2")
        Set R3 = ActiveSheet.Range("B3")
        Set rng1 = Range(Cells(1, "C"), Cells(R3, "C"))
        Application.ScreenUpdating = False
        Columns("C:C").ClearContents
        With rng1
            .Formula = "=RAND()*(" & (R1 - R2) + R2 & ")"
            .Copy
            .PasteSpecial Paste:=xlPasteValues
        End With
        cel.Select
        Application.CutCopyMode = False
        Application.ScreenUpdating = True
    End Sub

  19. #19
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,443
    Location
    Try

    [vba]

    Sub Test()
    Dim rng1, cell, R1 As Double, R2 As Double, R3 As Long
    R1 = ActiveSheet.Range("B1").Value2
    R2 = ActiveSheet.Range("B2").Value2
    R3 = ActiveSheet.Range("B3").Value2

    Application.ScreenUpdating = False
    Columns("C:C").ClearContents
    With Range("C1").Resize(R3)

    .Formula = "=RAND()*(" & R2 & "-" & R1 & ")+" & R1
    .Value = .Value
    End With
    Application.ScreenUpdating = True
    End Sub
    [/vba]
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •