## How to create random numbers, text strings, dates and time values

In excel the RAND() function returns a number greater than or equal to 0 (zero) and less than 1. Combining the RAND() function with a few other functions makes it possible to create random numbers, text, dates and time values.

**Table of contents**

Formula in cell A1:

RAND() function returns a number greater than or equal to 0 (zero) and less than 1 every time a sheet is recalculated. Pressing F9 recalculates all sheets in all open workbooks. The RAND function is a volatile function.

How to return numbers between or equal to 0 and 100?

Formula in cell A3:

How to return numbers between or equal to -50 and 50?

Formula in cell A5:

ROUNDUP(number, num_digits) - Rounds a number up, away from zero.

**Random text strings**

A character in excel is represented by a number. A to Z are 65 to 90 and a to z are 97 to 122. =CHAR(number) returns the character specified by the code number from the character set of your computer. You can use the CHAR, RAND and ROUNDUP function to return random characters, let me show you how.

A random uppercase letter

Formula in A1:

A random lowercase letter

Formula in B1:

A random lowercase or uppercase letter

Formula in C1:

Three random uppercase letters

Formula in A2:

Three random lowercase letters

Formula in B2:

Three random lowercase and uppercase letters

Formula in C2:

Excel uses numbers as dates, called 1900-system. The earliest date you can use is 1900-01-01 and it is represented by number 1. 2012-01-01 is 40909 and is also 40909 days later from the date 1900-01-01.

Now we know how dates in excel work, let´s say you want to create a random number between 2012-01-01 and 2012-12-31. 2012-01-01 is 40909 and 2012-12-31 is 41274. 41274 - 40909 = 365 days. Time to construct the formula.

Formula in cell A7:

**Random time values**

Random hours, minutes and seconds

Formula in cell B3:

Cell B3 is formatted as time.

Random hours

Formula in cell B4:

Random minutes

Formula in cell B5:

Random hours and minutes

Formula in cell B6:

Random minutes and seconds

Formula in cell B7:

**Download excel *.xlsx file**

Quickly jump to last row in a data set using excel hyperlink function

Today I´ll show you how to create a useful hyperlink in excel. If you click the link it will take […]

Quickly select a data set or an excel defined table [HYPERLINK]

If you often copy data sets or tables, the following technique might be interesting! The animated gif shows two hyperlinks, […]

Question: I am trying to create an excel spreadsheet that has a date range.Example: Cell A1 1/4/2009-1/10/2009 Cell B1 1/11/2009-1/17/2009 […]

Formula for matching a date within a date range

Table of contents Match a date when a date range is entered in a single cell Match a date when […]

The image above demonstrates an array formula in cell E4 that searches for the closest date in column A to the […]

I read an interesting blog post Is A Particular Word Contained In A Text String? on Spreadsheetpage. That inspired me […]

Table of contents Initials from first and last names Initials from first, middle and last names Create middle name initials […]

Convert array formula to a regular formula

Kamran Mumtaz asked: Is there any way to use VLOOKUP for multiple criteria and I do not want to use CSE?; […]

How to generate random numbers and text

What's on this page Random numbers with a decimal Random negative numbers with two decimals Random negative numbers with three […]

The RAND function calculates a random real number greater than or equal to 0 and less than 1. The function […]

Highlight specific time ranges in a weekly schedule

In a previous post I created a simple weekly schedule with dynamic dates. In this post I am going to […]

I have built a sheet to track time at work. It is very simple, there are 13 sheets, one for each […]

Count entries between date and time criteria

Question: My issue is that I get the date in this format: 7/23/2011 7:00:00 AM I am trying to count […]

### 2 Responses to “How to create random numbers, text strings, dates and time values”

### Leave a Reply

### How to comment

**How to add a formula to your comment**

<code>Insert your formula here.</code>

**Convert less than and larger than signs**

Use html character entities instead of less than and larger than signs.

< becomes < and > becomes >

**How to add VBA code to your comment**

[vb 1="vbnet" language=","]

Put your VBA code here.

[/vb]

**How to add a picture to your comment:**

Upload picture to postimage.org or imgur

Use the img tag, like this: <img src="Insert pic link here">

**Contact Oscar**

You can contact me through this contact form

You can simplify your random upper or lower case letter formula like this...

=CHAR((ROUNDUP(RAND()*26,0)+64+32*(RAND()<0.5)))

and, of course, you can simplify your 3 upper or lower case letters formula using this as well.

Rick Rothstein (MVP - Excel),

Thanks!!