+ Reply to Thread
Results 1 to 3 of 3

Thread: Random Text in a userform textbox

  1. #1
    Soniya
    Guest

    Random Text in a userform textbox

    Hi All,

    Is it possible to display random text from a range of cells in a
    userform textbox when the userform is activated?

    Also if the range refers to non contiguous cells.

    Thanks


  2. #2
    Toppers
    Guest

    RE: Random Text in a userform textbox

    Hi,
    Something like this? Put in "Userform_Initialize" routine

    Set rng = Range("A1:B1,B3,C5,B8,C10")
    mystr = ""
    For Each cell In rng
    mystr = mystr + cell.Value & " "
    Next
    textbox1.Text = mystr

    "Soniya" wrote:

    > Hi All,
    >
    > Is it possible to display random text from a range of cells in a
    > userform textbox when the userform is activated?
    >
    > Also if the range refers to non contiguous cells.
    >
    > Thanks
    >
    >


  3. #3
    Tom Ogilvy
    Guest

    Re: Random Text in a userform textbox

    If you only want the text from one cell on a random selection then
    To randomize you could do:

    Dim rng as Range, i as Long, j as Long
    Dim cell as Range
    Set rng = Range("A1:B1,B3,C5,B8,C10")
    i = int(rnd()*rng.count+1)
    j = 0
    For Each cell In rng
    j = j +1
    if j = i then
    TextBox1.Text = cell.Value
    exit for
    End if
    Next

    --
    Regards,
    Tom Ogilvy

    "Toppers" <Toppers@discussions.microsoft.com> wrote in message
    news:9EE4E4AC-C109-46DE-83BB-02A08951225D@microsoft.com...
    > Hi,
    > Something like this? Put in "Userform_Initialize" routine
    >
    > Set rng = Range("A1:B1,B3,C5,B8,C10")
    > mystr = ""
    > For Each cell In rng
    > mystr = mystr + cell.Value & " "
    > Next
    > textbox1.Text = mystr
    >
    > "Soniya" wrote:
    >
    > > Hi All,
    > >
    > > Is it possible to display random text from a range of cells in a
    > > userform textbox when the userform is activated?
    > >
    > > Also if the range refers to non contiguous cells.
    > >
    > > Thanks
    > >
    > >




+ 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.2.0