+ Reply to Thread
Results 1 to 3 of 3

about random no

  1. #1
    Registered User
    Join Date
    05-03-2006
    Posts
    46

    about random no

    anyone can do a micro for me please?

    a1 has 1 number and it changes manully by me.

    say a1 is 7,
    what i want is when i click the button(with micro), b1-b30 will fill with random numbers between 1-11, but the number in any of this column can't be same as a1.
    so, b1-b30 will have number between 1-11, but no 7 inside.
    when i change a1 to 9, no 9 shows in b1-b30.

  2. #2
    Toppers
    Guest

    RE: about random no

    Try:

    Sub a()
    with worksheets("Sheet1")
    For i = 1 To 30
    Do
    n = Int(Rnd() * 11 + 1)
    Loop Until n <>. Range("A1")
    ..Cells(i, "B") = n
    Next i
    end with
    End Sub

    HTH

    "jinvictor" wrote:

    >
    > anyone can do a micro for me please?
    >
    > a1 has 1 number and it changes manully by me.
    >
    > say a1 is 7,
    > what i want is when i click the button(with micro), b1-b30 will fill
    > with random numbers between 1-11, but the number in any of this column
    > can't be same as a1.
    > so, b1-b30 will have number between 1-11, but no 7 inside.
    > when i change a1 to 9, no 9 shows in b1-b30.
    >
    >
    > --
    > jinvictor
    > ------------------------------------------------------------------------
    > jinvictor's Profile: http://www.excelforum.com/member.php...o&userid=34099
    > View this thread: http://www.excelforum.com/showthread...hreadid=555482
    >
    >


  3. #3
    Bob Phillips
    Guest

    Re: about random no

    Private Sub Worksheet_Change(ByVal Target As Range)
    Const WS_RANGE As String = "A1"
    Dim tmp
    Dim i As Long

    On Error GoTo ws_exit:
    Application.EnableEvents = False
    For i = 1 To 30
    Do
    tmp = Int(Rnd() * 11 + 1)
    Loop Until tmp <> Target.Value
    Me.Cells(i, "B").Value = tmp
    Next i

    ws_exit:
    Application.EnableEvents = True
    End Sub

    'This is worksheet event code, which means that it needs to be
    'placed in the appropriate worksheet code module, not a standard
    'code module. To do this, right-click on the sheet tab, select
    'the View Code option from the menu, and paste the code in.



    --
    HTH

    Bob Phillips

    (replace somewhere in email address with gmail if mailing direct)

    "jinvictor" <[email protected]> wrote
    in message news:[email protected]...
    >
    > anyone can do a micro for me please?
    >
    > a1 has 1 number and it changes manully by me.
    >
    > say a1 is 7,
    > what i want is when i click the button(with micro), b1-b30 will fill
    > with random numbers between 1-11, but the number in any of this column
    > can't be same as a1.
    > so, b1-b30 will have number between 1-11, but no 7 inside.
    > when i change a1 to 9, no 9 shows in b1-b30.
    >
    >
    > --
    > jinvictor
    > ------------------------------------------------------------------------
    > jinvictor's Profile:

    http://www.excelforum.com/member.php...o&userid=34099
    > View this thread: http://www.excelforum.com/showthread...hreadid=555482
    >




+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1