• Home
  • Blog
  • Resume
  • Contact
  • Projects
  • Gallery
  • Amit’s Resume
  • About Nagpur
KEEP IN TOUCH

Random Text Generator

Oct23
2005
2 Comments Written by admin

This function will return random text (a-z) for the specified length. For ex. Randtxt(5) will return xythp.

‘—————————————————————————————
‘ Procedure : Randtxt
‘ DateTime  : 10/23/2005 11:54
‘ Author    : Ashutosh
‘ Purpose   :This function will return random text for the specified no. of chars

Function Randtxt(nochars As Byte) As String
    On Error GoTo Randtxt_Error
    If nochars = 0 Then Exit Function
    Dim sResult As String, i As Long
        sResult = “”
        For i = 1 To nochars
           sResult = sResult & Chr(Int(Rnd * (122 – 97) + 97))
        Next i
    Randtxt = sResult
    Exit Function
Randtxt_Error:
    MsgBox “Error ” & Err.Number & ” (” & Err.Description & “) in function Randtxt”
End Function

This sub will return random text for the specified length and number of random texts needed.

‘ Procedure : Randtxt1
‘ DateTime  : 10/23/2005 12:12
‘ Author    : Ashutosh
‘ Purpose   : This sub will return and no. of random text random text for the
‘specified no. of chars needed starting from the activecell
Sub Randtxt1()
Dim nochars As Byte
Dim nos As Long
nochars = InputBox(“Enter the length of the random text”, , 1)
nos = InputBox(“Enter the number the random texts needed”, , 1)
    On Error GoTo Randtxt_Error1
    If nochars = 0 Then Exit Sub
    Dim sResult As String, i As Long, j As Long
    For j = 1 To nos
        sResult = “”
        For i = 1 To nochars
           sResult = sResult & Chr(Int(Rnd * (122 – 97) + 97))
        Next i
            ActiveCell.Offset(j – 1, 0) = sResult
    Next j
    Exit Sub
Randtxt_Error1:
    MsgBox “Error ” & Err.Number & ” (” & Err.Description & _
        ”) in procedure Randtxt”
End Sub

Related posts:

  1. Excel Instructions – Exponential Distribution
  2. String Operations
  3. PMT Worksheet Function
  4. Excel Function to check if text is palindrome or not
Posted in String Operations - Tagged Number Err
SHARE THIS Twitter Facebook Delicious StumbleUpon E-mail
« Microsoft Office Assistance: Summing up ways to add and count Excel data
» Add footer to all the worksheets in a workbook

2 Comments

  1. Jason's Gravatar Jason
    February 28, 2008 at 8:24 pm | Permalink

    This is a great little script. However, it needs to be incremented in the range to 26 letters so Z’s will appear.

    Others may also appreciate an option with capital letters.

  2. Filo Kirk's Gravatar Filo Kirk
    June 6, 2008 at 9:11 am | Permalink

    I used this for a cell but the text wasn’t long enough so I used concatenate to make the string longer…=CONCATENATE(randtxt(200),randtxt(200),randtxt(200),randtxt(200),randtxt(200))

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

*

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="">

Tags

Access Alt F8 Books boxplot cells charts count cursor dashboard data mining dbase design error excel excel functions export filter flip LaTex MS query Number Err ODBC pipes Press Alt F11 Public Sub python R random numbers Range Cells report scripting software sparklines SQL SQL server stack columns statistics stemming string tag cloud text mining UDF VBA visualization wildcard

Network

View Ashutosh Nandeshwar's profile on LinkedIn

Recent Comments

  • W. McNabb on The search key was not found in any record in Access
  • Manuel on The search key was not found in any record in Access
  • Wendy Naples on The search key was not found in any record in Access
  • larry on Access Export to Excel (2007)
  • Betty Chou on Projects

Related Posts

  1. Excel Instructions – Exponential Distribution
  2. String Operations
  3. PMT Worksheet Function
  4. Excel Function to check if text is palindrome or not

EvoLve theme by Blogatize  •  Powered by WordPress nandeshwar.info