ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Discussion (Misc queries) (https://www.excelbanter.com/excel-discussion-misc-queries/)
-   -   Random text via Macro button (https://www.excelbanter.com/excel-discussion-misc-queries/194317-random-text-via-macro-button.html)

MarkV

Random text via Macro button
 
Hi All

Anyone that can assist with my request will be greatly thanked.

I have a button that generate a random number in a given cell, now is it
possible to have a button that will display text upon clicking it?
It will off course be pre-typed text that will be randomized.

thanks all

Mike H

Random text via Macro button
 
Hi,

Have a look here on how to produce random text strings

http://www.vbaexpress.com/kb/getarticle.php?kb_id=110

Mike

"Markv" wrote:

Hi All

Anyone that can assist with my request will be greatly thanked.

I have a button that generate a random number in a given cell, now is it
possible to have a button that will display text upon clicking it?
It will off course be pre-typed text that will be randomized.

thanks all


MarkV

Random text via Macro button
 
thanks Mike appreciate it very much.

How do I implement this to a button? And one last question. I have heard
of there is a way to display pre-typed text in a window that appears every
now and then and disappears again.

Is this possible?

"Mike H" wrote:

Hi,

Have a look here on how to produce random text strings

http://www.vbaexpress.com/kb/getarticle.php?kb_id=110

Mike

"Markv" wrote:

Hi All

Anyone that can assist with my request will be greatly thanked.

I have a button that generate a random number in a given cell, now is it
possible to have a button that will display text upon clicking it?
It will off course be pre-typed text that will be randomized.

thanks all


Mike H

Random text via Macro button
 
Hi,

With apologies to the original author the function can be converted to a sub
like this.
Put this in a general module and then from the worksheet:-

View toolbars forms
Click the button icon on the 'Forms' toolbar and put a button on your sheet.
Select 'This Workbook' in the dropdown and select the macro called RL and
click OK
Clicking the button will put the random string in the active cell.

is a way to display pre-typed text in a window that appears every
now and then and disappears again.


I don't understand what is means


Option Explicit
Sub RL()
Dim Cnt1 As Integer
Dim Cnt2 As Integer
Dim MySet As Integer
Dim Rand As String
Dim i As Integer, RndNo As Integer, XSet As Integer
Dim MyCase As Integer
Cnt1 = Range("A1").Value
Cnt2 = Range("A2").Value
MySet = Range("A3").Value
Application.Volatile
Select Case MySet
Case Is = "1" 'Upper case
MyCase = 65: XSet = 26
Case Is = "2" 'Lower Case
MyCase = 97: XSet = 26
Case Is = "3" 'Leading Capital
MyCase = 97: XSet = 26
Case Is = "4" 'Text digits
MyCase = 48: XSet = 10
Case Is = "5" 'Numeric digits
MyCase = 48: XSet = 10
End Select

If MySet = 3 Then 'Set leading character of "Name"
i = i + 1
Randomize
Rand = Rand & Chr(Int((26) * Rnd + 65))
End If
'Set random length of string
RndNo = Int((Cnt2 + 1 - Cnt1) * Rnd + Cnt1)
Do
i = i + 1
Randomize
Rand = Rand & Chr(Int((XSet) * Rnd + MyCase))
Loop Until i = RndNo
ActiveCell.Value = Rand
'Convert string to number
If MySet = 5 Then ActiveCell.Value = ActiveCell.Value * 1

End Sub

"Markv" wrote:

thanks Mike appreciate it very much.

How do I implement this to a button? And one last question. I have heard
of there is a way to display pre-typed text in a window that appears every
now and then and disappears again.

Is this possible?

"Mike H" wrote:

Hi,

Have a look here on how to produce random text strings

http://www.vbaexpress.com/kb/getarticle.php?kb_id=110

Mike

"Markv" wrote:

Hi All

Anyone that can assist with my request will be greatly thanked.

I have a button that generate a random number in a given cell, now is it
possible to have a button that will display text upon clicking it?
It will off course be pre-typed text that will be randomized.

thanks all



All times are GMT +1. The time now is 06:56 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com