RandBetweenText Function

RandBetweenText Formula in Excel

In this article, we have created a user defined function RandBetweenText in Excel. This function returns random text from the selected range. You can use this function to distribute the text randomly or to create the dummy data set.

Here we have create a dummy data using RandBetweenText  function-

Dummy data created using RandBetweenText
Dummy data created using RandBetweenText

Watch the step by step video tutorial:

Below is the VBA code for this UDF-

Option Explicit

Function RandBetweenText(Input_Value As Range) As String


Dim rng As Range
Dim Random_Values As String

For Each rng In Input_Value
  If Random_Values = "" Then
     Random_Values = rng.Value
     Random_Values = Random_Values & "," & rng.Value
  End If

Dim arr As Variant
arr = Split(Random_Values, ",")

Dim n As Integer
n = UBound(arr)

RandBetweenText = arr(Application.WorksheetFunction.RandBetween(0, n))

End Function


Click here to download this practice file.

My Name is PK. I am founder of PK-AnExcelExpert.com. I am a Microsoft Certified Professional. I have more than 10 years of experience in Data Visualization, Excel Automation and dashboard creation. Excel is my passion and I like to do always something innovative in Excel and share it with other people.