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
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
>
>
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
> >
> >
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks